From 179ff72b718b490e590c41a45593a59cb5f56706 Mon Sep 17 00:00:00 2001 From: Courtney Holcomb Date: Mon, 30 Sep 2024 07:29:33 -0700 Subject: [PATCH] WIP --- metricflow/plan_conversion/dataflow_to_sql.py | 43 +- .../DuckDB/test_conversion_metric__plan0.sql | 558 +-- ...est_conversion_metric__plan0_optimized.sql | 72 +- ..._metric_with_categorical_filter__plan0.sql | 599 +-- ...th_categorical_filter__plan0_optimized.sql | 88 +- ...ion_metric_with_time_constraint__plan0.sql | 740 ++- ..._with_time_constraint__plan0_optimized.sql | 72 +- ...t_conversion_metric_with_window__plan0.sql | 564 +-- ...on_metric_with_window__plan0_optimized.sql | 74 +- ...with_window_and_time_constraint__plan0.sql | 783 ++- ...w_and_time_constraint__plan0_optimized.sql | 90 +- ...nversion_count_with_no_group_by__plan0.sql | 569 +-- ...ount_with_no_group_by__plan0_optimized.sql | 52 +- ...timespine_and_fill_nulls_with_0__plan0.sql | 636 ++- ...and_fill_nulls_with_0__plan0_optimized.sql | 94 +- .../DuckDB/test_conversion_rate__plan0.sql | 598 +-- .../test_conversion_rate__plan0_optimized.sql | 72 +- ...n_rate_with_constant_properties__plan0.sql | 682 ++- ...h_constant_properties__plan0_optimized.sql | 114 +- ...onversion_rate_with_no_group_by__plan0.sql | 569 +-- ...rate_with_no_group_by__plan0_optimized.sql | 52 +- ...est_conversion_rate_with_window__plan0.sql | 647 ++- ...sion_rate_with_window__plan0_optimized.sql | 90 +- ...nversion_count_with_no_group_by__plan0.xml | 2039 +++----- ...timespine_and_fill_nulls_with_0__plan0.xml | 2088 ++++---- .../test_conversion_rate__plan0.xml | 2074 ++++---- ...n_rate_with_constant_properties__plan0.xml | 2116 ++++---- ...onversion_rate_with_no_group_by__plan0.xml | 2037 +++----- ...est_conversion_rate_with_window__plan0.xml | 2100 ++++---- ..._metric_with_non_default_grains__plan0.sql | 263 +- ...th_non_default_grains__plan0_optimized.sql | 22 +- .../DuckDB/test_cumulative_metric__plan0.sql | 115 +- ...cumulative_metric_grain_to_date__plan0.sql | 115 +- .../test_cumulative_metric_month__plan0.sql | 212 +- ...mulative_metric_month__plan0_optimized.sql | 18 +- .../test_cumulative_metric_no_ds__plan0.sql | 107 +- ...est_cumulative_metric_no_window__plan0.sql | 115 +- ..._no_window_with_time_constraint__plan0.sql | 295 +- ..._with_time_constraint__plan0_optimized.sql | 16 +- ...c_with_agg_time_and_metric_time__plan0.sql | 231 +- ..._time_and_metric_time__plan0_optimized.sql | 16 +- ..._metric_with_agg_time_dimension__plan0.sql | 215 +- ...th_agg_time_dimension__plan0_optimized.sql | 10 +- ...th_multiple_agg_time_dimensions__plan0.sql | 231 +- ...e_agg_time_dimensions__plan0_optimized.sql | 16 +- ...multiple_metric_time_dimensions__plan0.sql | 231 +- ...etric_time_dimensions__plan0_optimized.sql | 16 +- ...with_non_adjustable_time_filter__plan0.sql | 533 +- ...djustable_time_filter__plan0_optimized.sql | 10 +- ...e_metric_with_non_default_grain__plan0.sql | 243 +- ...ith_non_default_grain__plan0_optimized.sql | 18 +- ...ive_metric_with_time_constraint__plan0.sql | 303 +- ..._with_time_constraint__plan0_optimized.sql | 18 +- ..._metric_with_non_default_grains__plan0.sql | 251 +- ...th_non_default_grains__plan0_optimized.sql | 22 +- ...e_metric_with_non_default_grain__plan0.sql | 251 +- ...ith_non_default_grain__plan0_optimized.sql | 20 +- ..._metric_with_non_default_grains__plan0.sql | 271 +- ...th_non_default_grains__plan0_optimized.sql | 24 +- ...w_metric_with_non_default_grain__plan0.sql | 247 +- ...ith_non_default_grain__plan0_optimized.sql | 20 +- ..._metric_with_non_default_grains__plan0.sql | 601 +-- ...th_non_default_grains__plan0_optimized.sql | 38 +- ..._metric_with_custom_granularity__plan0.sql | 243 +- ...th_custom_granularity__plan0_optimized.sql | 43 +- ..._metric_with_custom_granularity__plan0.sql | 656 +-- ...th_custom_granularity__plan0_optimized.sql | 11 +- ...ity_joined_to_non_default_grain__plan0.sql | 233 +- ..._to_non_default_grain__plan0_optimized.sql | 24 +- ...metrics_with_custom_granularity__plan0.sql | 557 +-- ...th_custom_granularity__plan0_optimized.sql | 50 +- ...ity_joined_to_non_default_grain__plan0.sql | 654 +-- ..._to_non_default_grain__plan0_optimized.sql | 22 +- ..._custom_granularity_metric_time__plan0.sql | 75 +- ...anularity_metric_time__plan0_optimized.sql | 11 +- ...tom_granularity_non_metric_time__plan0.sql | 109 +- ...arity_non_metric_time__plan0_optimized.sql | 9 +- ..._with_custom_granularity_filter__plan0.sql | 198 +- ...om_granularity_filter__plan0_optimized.sql | 8 +- ...nularity_in_filter_and_group_by__plan0.sql | 198 +- ...n_filter_and_group_by__plan0_optimized.sql | 8 +- ..._metric_with_custom_granularity__plan0.sql | 319 +- ...th_custom_granularity__plan0_optimized.sql | 18 +- ..._with_custom_granularity_filter__plan0.sql | 325 +- ...om_granularity_filter__plan0_optimized.sql | 18 +- ...nularity_in_filter_and_group_by__plan0.sql | 333 +- ...n_filter_and_group_by__plan0_optimized.sql | 18 +- .../test_build_metric_tasks__query0.sql | 2 +- .../test_build_saved_query_tasks__query0.sql | 13 +- .../test_combined_metrics_plan__ep_0.xml | 32 +- .../DuckDB/test_joined_plan__ep_0.xml | 14 +- .../test_multihop_joined_plan__ep_0.xml | 11 +- ...test_small_combined_metrics_plan__ep_0.xml | 16 +- .../test_combine_output_node__plan0.sql | 234 +- ...t_combine_output_node__plan0_optimized.sql | 32 +- .../test_compute_metrics_node__plan0.sql | 198 +- ..._compute_metrics_node__plan0_optimized.sql | 16 +- ...o_from_multiple_semantic_models__plan0.sql | 986 ++-- ...tiple_semantic_models__plan0_optimized.sql | 50 +- ...atio_from_single_semantic_model__plan0.sql | 204 +- ...single_semantic_model__plan0_optimized.sql | 20 +- ...ompute_metrics_node_simple_expr__plan0.sql | 196 +- ...rics_node_simple_expr__plan0_optimized.sql | 2 +- .../test_constrain_time_range_node__plan0.sql | 117 +- ...train_time_range_node__plan0_optimized.sql | 2 +- ...on_with_joined_where_constraint__plan0.sql | 352 +- ...ined_where_constraint__plan0_optimized.sql | 2 +- .../test_dimensions_requiring_join__plan0.sql | 234 +- ...nsions_requiring_join__plan0_optimized.sql | 2 - .../DuckDB/test_filter_node__plan0.sql | 97 +- .../test_filter_node__plan0_optimized.sql | 2 +- ...lter_with_where_constraint_node__plan0.sql | 105 +- ...where_constraint_node__plan0_optimized.sql | 8 +- ...spine_node_with_offset_to_grain__plan0.sql | 327 +- ..._with_offset_to_grain__plan0_optimized.sql | 16 +- ...e_spine_node_with_offset_window__plan0.sql | 327 +- ...de_with_offset_window__plan0_optimized.sql | 16 +- ..._time_spine_node_without_offset__plan0.sql | 327 +- ...e_node_without_offset__plan0_optimized.sql | 16 +- .../test_measure_aggregation_node__plan0.sql | 113 +- ...sure_aggregation_node__plan0_optimized.sql | 2 +- .../DuckDB/test_multi_join_node__plan0.sql | 251 +- .../test_multi_join_node__plan0_optimized.sql | 36 +- .../DuckDB/test_order_by_node__plan0.sql | 131 +- .../test_order_by_node__plan0_optimized.sql | 8 +- .../DuckDB/test_single_join_node__plan0.sql | 176 +- ...test_single_join_node__plan0_optimized.sql | 14 +- .../test_combine_output_node__plan0.xml | 821 +--- .../test_compute_metrics_node__plan0.xml | 784 +-- ...o_from_multiple_semantic_models__plan0.xml | 4294 ++++++----------- ...atio_from_single_semantic_model__plan0.xml | 793 +-- ...ompute_metrics_node_simple_expr__plan0.xml | 782 +-- .../test_constrain_time_range_node__plan0.xml | 413 +- ...on_with_joined_where_constraint__plan0.xml | 1057 ++-- .../test_dimensions_requiring_join__plan0.xml | 698 +-- .../SqlQueryPlan/test_filter_node__plan0.xml | 276 +- ...lter_with_where_constraint_node__plan0.xml | 347 +- ...spine_node_with_offset_to_grain__plan0.xml | 1335 ++--- ...e_spine_node_with_offset_window__plan0.xml | 1335 ++--- ..._time_spine_node_without_offset__plan0.xml | 1335 ++--- .../test_measure_aggregation_node__plan0.xml | 359 +- .../test_multi_join_node__plan0.xml | 799 +-- .../test_order_by_node__plan0.xml | 476 +- .../test_single_join_node__plan0.xml | 577 +-- ...set_metric_with_time_constraint__plan0.sql | 749 ++- ..._with_time_constraint__plan0_optimized.sql | 26 +- .../DuckDB/test_derived_metric__plan0.sql | 624 +-- .../test_derived_metric__plan0_optimized.sql | 4 +- ...nth_dimension_and_offset_window__plan0.sql | 150 +- ...ion_and_offset_window__plan0_optimized.sql | 12 +- ...ved_metric_with_offset_to_grain__plan0.sql | 682 +-- ..._with_offset_to_grain__plan0_optimized.sql | 30 +- ...offset_to_grain_and_granularity__plan0.sql | 684 +-- ...grain_and_granularity__plan0_optimized.sql | 32 +- ...rived_metric_with_offset_window__plan0.sql | 682 +-- ...ic_with_offset_window__plan0_optimized.sql | 30 +- ...h_offset_window_and_granularity__plan0.sql | 682 +-- ...indow_and_granularity__plan0_optimized.sql | 30 +- ...fset_window_and_offset_to_grain__plan0.sql | 1056 ++-- ...w_and_offset_to_grain__plan0_optimized.sql | 40 +- ...offset_to_grain_and_granularity__plan0.sql | 1058 ++-- ...grain_and_granularity__plan0_optimized.sql | 42 +- ...h_offset_window_and_time_filter__plan0.sql | 702 +-- ...indow_and_time_filter__plan0_optimized.sql | 30 +- ...erived_offset_cumulative_metric__plan0.sql | 739 ++- ...set_cumulative_metric__plan0_optimized.sql | 22 +- ...offset_metric_with_agg_time_dim__plan0.sql | 680 +-- ...ric_with_agg_time_dim__plan0_optimized.sql | 24 +- ...et_metric_with_one_input_metric__plan0.sql | 523 +- ...with_one_input_metric__plan0_optimized.sql | 14 +- .../test_multi_metric_fill_null__plan0.sql | 529 +- ...ulti_metric_fill_null__plan0_optimized.sql | 22 +- .../test_nested_derived_metric__plan0.sql | 1254 ++--- ...nested_derived_metric__plan0_optimized.sql | 24 +- ...d_where_constraint_not_selected__plan0.sql | 589 +-- ...nstraint_not_selected__plan0_optimized.sql | 34 +- ...h_offset_multiple_input_metrics__plan0.sql | 500 +- ...ultiple_input_metrics__plan0_optimized.sql | 30 +- ...d_fill_nulls_without_time_spine__plan0.sql | 311 +- ...ls_without_time_spine__plan0_optimized.sql | 8 +- ...without_time_spine_multi_metric__plan0.sql | 533 +- ...me_spine_multi_metric__plan0_optimized.sql | 24 +- .../DuckDB/test_nested_filters__plan0.sql | 1414 ++---- .../test_nested_filters__plan0_optimized.sql | 29 +- .../DuckDB/test_nested_offsets__plan0.sql | 541 +-- .../test_nested_offsets__plan0_optimized.sql | 26 +- ...ed_offsets_with_time_constraint__plan0.sql | 543 +-- ..._with_time_constraint__plan0_optimized.sql | 28 +- ...d_offsets_with_where_constraint__plan0.sql | 547 +-- ...with_where_constraint__plan0_optimized.sql | 28 +- ...ry_have_different_granularities__plan0.sql | 545 +-- ...fferent_granularities__plan0_optimized.sql | 18 +- ...n_metric_multiple_granularities__plan0.sql | 543 +-- ...ultiple_granularities__plan0_optimized.sql | 22 +- ...fset_to_grain_with_agg_time_dim__plan0.sql | 682 +-- ...ain_with_agg_time_dim__plan0_optimized.sql | 30 +- ...ry_have_different_granularities__plan0.sql | 880 ++-- ...fferent_granularities__plan0_optimized.sql | 28 +- ...w_metric_multiple_granularities__plan0.sql | 728 +-- ...ultiple_granularities__plan0_optimized.sql | 44 +- ...offset_window_with_agg_time_dim__plan0.sql | 682 +-- ...dow_with_agg_time_dim__plan0_optimized.sql | 30 +- ...set_metric_with_time_constraint__plan0.sql | 525 +- ..._with_time_constraint__plan0_optimized.sql | 16 +- ...values_with_a_join_and_a_filter__plan0.sql | 356 +- ...h_a_join_and_a_filter__plan0_optimized.sql | 2 +- .../test_dimensions_requiring_join__plan0.sql | 234 +- ...nsions_requiring_join__plan0_optimized.sql | 2 - ...values_with_a_join_and_a_filter__plan0.xml | 1066 ++-- .../test_dimensions_requiring_join__plan0.xml | 698 +-- .../test_cumulative_fill_nulls__plan0.sql | 541 +-- ...cumulative_fill_nulls__plan0_optimized.sql | 22 +- ...fill_nulls_for_one_input_metric__plan0.sql | 854 ++-- ..._for_one_input_metric__plan0_optimized.sql | 42 +- ...join_to_time_spine_with_filters__plan0.sql | 549 +-- ...me_spine_with_filters__plan0_optimized.sql | 18 +- ...e_fill_nulls_with_0_metric_time__plan0.sql | 317 +- ...ls_with_0_metric_time__plan0_optimized.sql | 14 +- ..._simple_fill_nulls_with_0_month__plan0.sql | 319 +- ...ll_nulls_with_0_month__plan0_optimized.sql | 16 +- ...th_0_with_categorical_dimension__plan0.sql | 303 +- ...categorical_dimension__plan0_optimized.sql | 4 +- ...lls_with_0_with_non_metric_time__plan0.sql | 303 +- ..._with_non_metric_time__plan0_optimized.sql | 4 +- ...e_fill_nulls_without_time_spine__plan0.sql | 303 +- ...ls_without_time_spine__plan0_optimized.sql | 4 +- ...st_offset_window_with_date_part__plan0.sql | 682 +-- ...window_with_date_part__plan0_optimized.sql | 30 +- ...with_joined_sub_daily_dimension__plan0.sql | 2093 ++++---- ...d_sub_daily_dimension__plan0_optimized.sql | 18 +- ...metric_with_sub_daily_dimension__plan0.sql | 576 +-- ...h_sub_daily_dimension__plan0_optimized.sql | 2 +- ...est_simple_query_with_date_part__plan0.sql | 303 +- ..._query_with_date_part__plan0_optimized.sql | 2 +- ..._query_with_multiple_date_parts__plan0.sql | 343 +- ...h_multiple_date_parts__plan0_optimized.sql | 2 +- .../test_sub_daily_dimension__plan0.sql | 190 +- ...t_sub_daily_dimension__plan0_optimized.sql | 2 +- .../test_sub_daily_metric_time__plan0.sql | 75 +- ...cumulative_grain_to_date_metric__plan0.sql | 985 ++-- ..._grain_to_date_metric__plan0_optimized.sql | 14 +- ...bdaily_cumulative_window_metric__plan0.sql | 985 ++-- ...ulative_window_metric__plan0_optimized.sql | 14 +- ...ides_metric_default_granularity__plan0.sql | 591 +-- ...c_default_granularity__plan0_optimized.sql | 12 +- ...daily_join_to_time_spine_metric__plan0.sql | 591 +-- ..._to_time_spine_metric__plan0_optimized.sql | 12 +- ...subdaily_offset_to_grain_metric__plan0.sql | 981 ++-- ...ffset_to_grain_metric__plan0_optimized.sql | 14 +- ...t_subdaily_offset_window_metric__plan0.sql | 981 ++-- ..._offset_window_metric__plan0_optimized.sql | 14 +- ...ily_time_constraint_with_metric__plan0.sql | 987 ++-- ...onstraint_with_metric__plan0_optimized.sql | 16 +- ...time_constraint_without_metrics__plan0.sql | 133 +- ...values_query_with_metric_filter__plan0.sql | 367 +- ...ry_with_metric_filter__plan0_optimized.sql | 10 +- ...emantic_model_as_queried_metric__plan0.sql | 660 +-- ...del_as_queried_metric__plan0_optimized.sql | 12 +- ...t_filter_with_conversion_metric__plan0.sql | 849 ++-- ...ith_conversion_metric__plan0_optimized.sql | 80 +- ...roup_by_has_local_entity_prefix__plan0.sql | 672 +-- ...s_local_entity_prefix__plan0_optimized.sql | 44 +- .../test_inner_query_multi_hop__plan0.sql | 1060 ++-- ...inner_query_multi_hop__plan0_optimized.sql | 51 +- .../test_inner_query_single_hop__plan0.sql | 355 +- ...nner_query_single_hop__plan0_optimized.sql | 13 +- .../test_metric_filtered_by_itself__plan0.sql | 658 +-- ...ic_filtered_by_itself__plan0_optimized.sql | 12 +- ...ric_with_metric_in_where_filter__plan0.sql | 579 +-- ...etric_in_where_filter__plan0_optimized.sql | 16 +- ...mulative_metric_in_where_filter__plan0.sql | 377 +- ...etric_in_where_filter__plan0_optimized.sql | 12 +- ..._derived_metric_in_where_filter__plan0.sql | 792 ++- ...etric_in_where_filter__plan0_optimized.sql | 30 +- ...with_multiple_metrics_in_filter__plan0.sql | 903 ++-- ...ple_metrics_in_filter__plan0_optimized.sql | 20 +- ...th_ratio_metric_in_where_filter__plan0.sql | 908 ++-- ...etric_in_where_filter__plan0_optimized.sql | 14 +- ...h_simple_metric_in_where_filter__plan0.sql | 565 +-- ...etric_in_where_filter__plan0_optimized.sql | 14 +- ...uery_with_metric_time_dimension__plan0.sql | 608 +-- ...metric_time_dimension__plan0_optimized.sql | 16 +- ...uery_with_metric_time_dimension__plan0.xml | 2581 ++++------ ...dimensions_with_time_constraint__plan0.sql | 432 +- .../DuckDB/test_metric_time_only__plan0.sql | 63 +- .../test_metric_time_quarter_alone__plan0.sql | 63 +- ...tric_time_with_other_dimensions__plan0.sql | 308 +- ...with_other_dimensions__plan0_optimized.sql | 2 - ...dimensions_with_time_constraint__plan0.xml | 1389 ++---- .../test_metric_time_only__plan0.xml | 126 +- .../test_metric_time_quarter_alone__plan0.xml | 126 +- ...tric_time_with_other_dimensions__plan0.xml | 917 +--- ...conversion_metric_query_filters__plan0.sql | 977 ++-- ..._metric_query_filters__plan0_optimized.sql | 138 +- ..._metric_with_query_time_filters__plan0.sql | 789 ++- ...th_query_time_filters__plan0_optimized.sql | 21 +- ...re_source_categorical_dimension__plan0.sql | 488 +- ...categorical_dimension__plan0_optimized.sql | 18 +- ...spine_metric_predicate_pushdown__plan0.sql | 1404 ++---- ...ic_predicate_pushdown__plan0_optimized.sql | 90 +- ...ic_time_filter_with_two_targets__plan0.sql | 551 +-- ...lter_with_two_targets__plan0_optimized.sql | 11 +- ..._categorical_dimension_pushdown__plan0.sql | 300 +- ...al_dimension_pushdown__plan0_optimized.sql | 13 +- ..._metric_with_query_time_filters__plan0.sql | 1372 ++---- ...th_query_time_filters__plan0_optimized.sql | 62 +- ...ry_with_metric_joins_and_filter__plan0.sql | 2032 +++----- ...tric_joins_and_filter__plan0_optimized.sql | 82 +- ...ine_pushdown_filter_application__plan0.sql | 343 +- ...wn_filter_application__plan0_optimized.sql | 16 +- ..._categorical_dimension_pushdown__plan0.sql | 551 +-- ...al_dimension_pushdown__plan0_optimized.sql | 11 +- .../DuckDB/test_skipped_pushdown__plan0.sql | 556 +-- ...test_skipped_pushdown__plan0_optimized.sql | 12 +- .../test_common_semantic_model__plan0.sql | 620 +-- ...common_semantic_model__plan0_optimized.sql | 2 +- .../DuckDB/test_distinct_values__plan0.sql | 191 +- .../test_distinct_values__plan0_optimized.sql | 2 +- ...th_where_constraint_on_join_dim__plan0.sql | 551 +-- ...onstraint_on_join_dim__plan0_optimized.sql | 11 +- .../test_join_to_scd_dimension__plan0.sql | 425 +- ...join_to_scd_dimension__plan0_optimized.sql | 15 +- .../DuckDB/test_limit_rows__plan0.sql | 309 +- .../test_limit_rows__plan0_optimized.sql | 2 +- ...al_dimension_using_local_entity__plan0.sql | 208 +- ...on_using_local_entity__plan0_optimized.sql | 2 +- .../DuckDB/test_measure_constraint__plan0.sql | 1429 ++---- ...st_measure_constraint__plan0_optimized.sql | 31 +- ..._constraint_with_reused_measure__plan0.sql | 488 +- ...t_with_reused_measure__plan0_optimized.sql | 18 +- ...aint_with_single_expr_and_alias__plan0.sql | 327 +- ...single_expr_and_alias__plan0_optimized.sql | 4 +- ..._multiple_sources_no_dimensions__plan0.sql | 507 +- ...sources_no_dimensions__plan0_optimized.sql | 6 +- .../test_min_max_metric_time__plan0.sql | 69 +- ...t_min_max_metric_time__plan0_optimized.sql | 2 +- .../test_min_max_metric_time_week__plan0.sql | 69 +- ..._max_metric_time_week__plan0_optimized.sql | 2 +- .../test_min_max_only_categorical__plan0.sql | 73 +- ..._max_only_categorical__plan0_optimized.sql | 4 +- .../DuckDB/test_min_max_only_time__plan0.sql | 105 +- ...est_min_max_only_time__plan0_optimized.sql | 4 +- .../test_min_max_only_time_quarter__plan0.sql | 105 +- ...max_only_time_quarter__plan0_optimized.sql | 4 +- ...multi_hop_through_scd_dimension__plan0.sql | 666 +-- ...through_scd_dimension__plan0_optimized.sql | 23 +- ...test_multi_hop_to_scd_dimension__plan0.sql | 637 +-- ..._hop_to_scd_dimension__plan0_optimized.sql | 27 +- .../DuckDB/test_multihop_node__plan0.sql | 780 ++- .../test_multihop_node__plan0_optimized.sql | 11 +- ..._multiple_metrics_no_dimensions__plan0.sql | 845 ++-- ...metrics_no_dimensions__plan0_optimized.sql | 8 +- ...imension_with_non_default_grain__plan0.sql | 327 +- ...ith_non_default_grain__plan0_optimized.sql | 8 +- .../DuckDB/test_partitioned_join__plan0.sql | 795 +-- ...test_partitioned_join__plan0_optimized.sql | 12 +- .../str/DuckDB/test_id_enumeration__query.sql | 18 +- .../str/DuckDB/test_render_query__query0.sql | 2 +- ...ne_with_queried_time_constraint__plan0.sql | 529 +- ...eried_time_constraint__plan0_optimized.sql | 18 +- .../test_simple_join_to_time_spine__plan0.sql | 317 +- ...le_join_to_time_spine__plan0_optimized.sql | 12 +- ..._join_to_time_spine_with_filter__plan0.sql | 337 +- ...ime_spine_with_filter__plan0_optimized.sql | 14 +- ..._time_spine_with_queried_filter__plan0.sql | 343 +- ...e_with_queried_filter__plan0_optimized.sql | 18 +- 366 files changed, 43172 insertions(+), 82208 deletions(-) diff --git a/metricflow/plan_conversion/dataflow_to_sql.py b/metricflow/plan_conversion/dataflow_to_sql.py index 64b8ff5561..8fd70948d4 100644 --- a/metricflow/plan_conversion/dataflow_to_sql.py +++ b/metricflow/plan_conversion/dataflow_to_sql.py @@ -801,28 +801,34 @@ def visit_write_to_result_table_node(self, node: WriteToResultTableNode) -> SqlD def visit_filter_elements_node(self, node: FilterElementsNode) -> SqlDataSet: """Generates the query that realizes the behavior of FilterElementsNode.""" - from_data_set: SqlDataSet = node.parent_node.accept(self) - output_instance_set = from_data_set.instance_set.transform(FilterElements(node.include_specs)) - from_data_set_alias = self._next_unique_table_alias() - - # Also, the output columns should always follow the resolver format. - output_instance_set = output_instance_set.transform(ChangeAssociatedColumns(self._column_association_resolver)) - - # This creates select expressions for all columns referenced in the instance set. - select_columns = output_instance_set.transform( - CreateSelectColumnsForInstances(from_data_set_alias, self._column_association_resolver) - ).as_tuple() + parent_data_set: SqlDataSet = node.parent_node.accept(self) + output_instance_set = parent_data_set.instance_set.transform(FilterElements(node.include_specs)) + output_column_names = [instance.associated_column.column_name for instance in output_instance_set.as_tuple] + output_select_columns = [ + select_column + for select_column in parent_data_set.checked_sql_select_node.select_columns + if select_column.column_alias in output_column_names + ] + # where is the limiting factor! need those columns in the select statement + # could have a conditional - use subquery if where clase, else don't + where = parent_data_set.checked_sql_select_node.where # If distinct values requested, group by all select columns. - group_bys = select_columns if node.distinct else () + group_bys = tuple(output_select_columns if node.distinct else parent_data_set.checked_sql_select_node.group_bys) return SqlDataSet( instance_set=output_instance_set, + # add method from parent node with override params sql_select_node=SqlSelectStatementNode.create( - description=node.description, - select_columns=select_columns, - from_source=from_data_set.checked_sql_select_node, - from_source_alias=from_data_set_alias, + description=node.parent_node.description + "\n" + node.description, + select_columns=tuple(output_select_columns), + from_source=parent_data_set.checked_sql_select_node.from_source, + from_source_alias=parent_data_set.checked_sql_select_node.from_source_alias, + join_descs=parent_data_set.checked_sql_select_node.join_descs, + where=where, group_bys=group_bys, + order_bys=parent_data_set.checked_sql_select_node.order_bys, + limit=parent_data_set.checked_sql_select_node.limit, + distinct=parent_data_set.checked_sql_select_node.distinct, ), ) @@ -1499,6 +1505,11 @@ def visit_join_to_custom_granularity_node(self, node: JoinToCustomGranularityNod from_source=parent_data_set.checked_sql_select_node.from_source, from_source_alias=parent_alias, join_descs=parent_data_set.checked_sql_select_node.join_descs + (join_description,), + where=parent_data_set.checked_sql_select_node.where, + group_bys=parent_data_set.checked_sql_select_node.group_bys, + order_bys=parent_data_set.checked_sql_select_node.order_bys, + limit=parent_data_set.checked_sql_select_node.limit, + distinct=parent_data_set.checked_sql_select_node.distinct, ), ) diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0.sql index 58ba934733..cca15b89cf 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0.sql @@ -1,72 +1,126 @@ -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day - , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate + subq_12.metric_time__day + , CAST(subq_12.buys AS DOUBLE) / CAST(NULLIF(subq_12.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day - , MAX(subq_4.visits) AS visits - , MAX(subq_14.buys) AS buys + COALESCE(subq_3.metric_time__day, subq_11.metric_time__day) AS metric_time__day + , MAX(subq_3.visits) AS visits + , MAX(subq_11.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , SUM(subq_3.visits) AS visits + subq_2.metric_time__day + , SUM(subq_2.visits) AS visits FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.visits + subq_1.metric_time__day + , subq_1.visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.visits + subq_0.ds__day AS metric_time__day + , subq_0.visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + WHERE metric_time__day = '2020-01-01' + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , SUM(subq_10.buys) AS buys + FROM ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys', 'metric_time__day'] + SELECT + subq_9.metric_time__day + , subq_9.buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_5.visits) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_5.ds__day) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_5.metric_time__day) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_5.user) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_8.mf_internal_uuid AS mf_internal_uuid + , subq_8.buys AS buys FROM ( -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors + subq_4.ds__day + , subq_4.ds__day AS metric_time__day + , subq_4.user + , subq_4.visits FROM ( -- Read Elements From Semantic Model 'visits_source' SELECT @@ -101,291 +155,137 @@ 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_0 - ) subq_1 - ) subq_2 - WHERE metric_time__day = '2020-01-01' - ) subq_3 - GROUP BY - subq_3.metric_time__day - ) subq_4 - FULL OUTER JOIN ( - -- Aggregate Measures - SELECT - subq_13.metric_time__day - , SUM(subq_13.buys) AS buys - FROM ( - -- Pass Only Elements: ['buys', 'metric_time__day'] - SELECT - subq_12.metric_time__day - , subq_12.buys - FROM ( - -- Find conversions for user within the range of INF - SELECT - subq_11.ds__day - , subq_11.metric_time__day - , subq_11.user - , subq_11.buys - , subq_11.visits - FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_7.visits) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_7.ds__day) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_7.metric_time__day) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS metric_time__day - , FIRST_VALUE(subq_7.user) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_10.mf_internal_uuid AS mf_internal_uuid - , subq_10.buys AS buys + ) subq_4 + ) subq_5 + INNER JOIN ( + -- Add column with generated UUID + 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.buy__ds__day + , subq_7.buy__ds__week + , subq_7.buy__ds__month + , subq_7.buy__ds__quarter + , subq_7.buy__ds__year + , subq_7.buy__ds__extract_year + , subq_7.buy__ds__extract_quarter + , subq_7.buy__ds__extract_month + , subq_7.buy__ds__extract_day + , subq_7.buy__ds__extract_dow + , subq_7.buy__ds__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.user + , subq_7.session_id + , subq_7.buy__user + , subq_7.buy__session_id + , subq_7.buys + , subq_7.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_6.ds__day - , subq_6.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.buy__ds__day + , subq_6.buy__ds__week + , subq_6.buy__ds__month + , subq_6.buy__ds__quarter + , subq_6.buy__ds__year + , subq_6.buy__ds__extract_year + , subq_6.buy__ds__extract_quarter + , subq_6.buy__ds__extract_month + , subq_6.buy__ds__extract_day + , subq_6.buy__ds__extract_dow + , subq_6.buy__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy , subq_6.user - , subq_6.visits + , subq_6.session_id + , subq_6.buy__user + , subq_6.buy__session_id + , subq_6.buys + , subq_6.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.visit__ds__day - , subq_5.visit__ds__week - , subq_5.visit__ds__month - , subq_5.visit__ds__quarter - , subq_5.visit__ds__year - , subq_5.visit__ds__extract_year - , subq_5.visit__ds__extract_quarter - , subq_5.visit__ds__extract_month - , subq_5.visit__ds__extract_day - , subq_5.visit__ds__extract_dow - , subq_5.visit__ds__extract_doy - , subq_5.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.user - , subq_5.session - , subq_5.visit__user - , subq_5.visit__session - , subq_5.referrer_id - , subq_5.visit__referrer_id - , subq_5.visits - , subq_5.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_5 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_6 ) subq_7 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_9.ds__day - , subq_9.ds__week - , subq_9.ds__month - , subq_9.ds__quarter - , subq_9.ds__year - , subq_9.ds__extract_year - , subq_9.ds__extract_quarter - , subq_9.ds__extract_month - , subq_9.ds__extract_day - , subq_9.ds__extract_dow - , subq_9.ds__extract_doy - , subq_9.buy__ds__day - , subq_9.buy__ds__week - , subq_9.buy__ds__month - , subq_9.buy__ds__quarter - , subq_9.buy__ds__year - , subq_9.buy__ds__extract_year - , subq_9.buy__ds__extract_quarter - , subq_9.buy__ds__extract_month - , subq_9.buy__ds__extract_day - , subq_9.buy__ds__extract_dow - , subq_9.buy__ds__extract_doy - , subq_9.metric_time__day - , subq_9.metric_time__week - , subq_9.metric_time__month - , subq_9.metric_time__quarter - , subq_9.metric_time__year - , subq_9.metric_time__extract_year - , subq_9.metric_time__extract_quarter - , subq_9.metric_time__extract_month - , subq_9.metric_time__extract_day - , subq_9.metric_time__extract_dow - , subq_9.metric_time__extract_doy - , subq_9.user - , subq_9.session_id - , subq_9.buy__user - , subq_9.buy__session_id - , subq_9.buys - , subq_9.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.buy__ds__day - , subq_8.buy__ds__week - , subq_8.buy__ds__month - , subq_8.buy__ds__quarter - , subq_8.buy__ds__year - , subq_8.buy__ds__extract_year - , subq_8.buy__ds__extract_quarter - , subq_8.buy__ds__extract_month - , subq_8.buy__ds__extract_day - , subq_8.buy__ds__extract_dow - , subq_8.buy__ds__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.user - , subq_8.session_id - , subq_8.buy__user - , subq_8.buy__session_id - , subq_8.buys - , subq_8.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 - ON - ( - subq_7.user = subq_10.user - ) AND ( - (subq_7.ds__day <= subq_10.ds__day) - ) - ) subq_11 - ) subq_12 - ) subq_13 + ) subq_8 + ON + (subq_5.user = subq_8.user) AND ((subq_5.ds__day <= subq_8.ds__day)) + ) subq_9 + ) subq_10 GROUP BY - subq_13.metric_time__day - ) subq_14 + subq_10.metric_time__day + ) subq_11 ON - subq_4.metric_time__day = subq_14.metric_time__day + subq_3.metric_time__day = subq_11.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_3.metric_time__day, subq_11.metric_time__day) +) subq_12 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0_optimized.sql index 8a91583adb..e476db830a 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , MAX(subq_20.visits) AS visits - , MAX(subq_30.buys) AS buys + COALESCE(subq_16.metric_time__day, subq_24.metric_time__day) AS metric_time__day + , MAX(subq_16.visits) AS visits + , MAX(subq_24.buys) AS buys FROM ( -- Constrain Output with WHERE -- Aggregate Measures @@ -22,11 +22,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_18 + ) subq_14 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__day - ) subq_20 + ) subq_16 FULL OUTER JOIN ( -- Find conversions for user within the range of INF -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -37,40 +37,40 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_23.visits) OVER ( + FIRST_VALUE(subq_18.visits) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_23.ds__day) OVER ( + , FIRST_VALUE(subq_18.ds__day) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_23.metric_time__day) OVER ( + , FIRST_VALUE(subq_18.metric_time__day) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_23.user) OVER ( + , FIRST_VALUE(subq_18.user) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_26.mf_internal_uuid AS mf_internal_uuid - , subq_26.buys AS buys + , subq_21.mf_internal_uuid AS mf_internal_uuid + , subq_21.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -81,7 +81,7 @@ FROM ( , user_id AS user , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_23 + ) subq_18 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -92,19 +92,19 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_26 + ) subq_21 ON ( - subq_23.user = subq_26.user + subq_18.user = subq_21.user ) AND ( - (subq_23.ds__day <= subq_26.ds__day) + (subq_18.ds__day <= subq_21.ds__day) ) - ) subq_27 + ) subq_22 GROUP BY metric_time__day - ) subq_30 + ) subq_24 ON - subq_20.metric_time__day = subq_30.metric_time__day + subq_16.metric_time__day = subq_24.metric_time__day GROUP BY - COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) -) subq_31 + COALESCE(subq_16.metric_time__day, subq_24.metric_time__day) +) subq_25 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0.sql index fc3d6d87f5..c962846fdc 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0.sql @@ -1,77 +1,143 @@ -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day - , subq_15.visit__referrer_id - , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate + subq_12.metric_time__day + , subq_12.visit__referrer_id + , CAST(subq_12.buys AS DOUBLE) / CAST(NULLIF(subq_12.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day - , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) AS visit__referrer_id - , MAX(subq_4.visits) AS visits - , MAX(subq_14.buys) AS buys + COALESCE(subq_3.metric_time__day, subq_11.metric_time__day) AS metric_time__day + , COALESCE(subq_3.visit__referrer_id, subq_11.visit__referrer_id) AS visit__referrer_id + , MAX(subq_3.visits) AS visits + , MAX(subq_11.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.visit__referrer_id - , SUM(subq_3.visits) AS visits + subq_2.metric_time__day + , subq_2.visit__referrer_id + , SUM(subq_2.visits) AS visits FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.visit__referrer_id - , subq_2.visits + subq_1.metric_time__day + , subq_1.visit__referrer_id + , subq_1.visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits', 'visit__referrer_id', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.visit__referrer_id - , subq_1.visits + subq_0.ds__day AS metric_time__day + , subq_0.visit__referrer_id + , subq_0.visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + WHERE visit__referrer_id = 'ref_id_01' + ) subq_2 + GROUP BY + subq_2.metric_time__day + , subq_2.visit__referrer_id + ) subq_3 + FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , subq_10.visit__referrer_id + , SUM(subq_10.buys) AS buys + FROM ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] + SELECT + subq_9.metric_time__day + , subq_9.visit__referrer_id + , subq_9.buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_5.visits) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_5.visit__referrer_id) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visit__referrer_id + , FIRST_VALUE(subq_5.ds__day) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_5.metric_time__day) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_5.user) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_8.mf_internal_uuid AS mf_internal_uuid + , subq_8.buys AS buys FROM ( -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user'] SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors + subq_4.ds__day + , subq_4.ds__day AS metric_time__day + , subq_4.user + , subq_4.visit__referrer_id + , subq_4.visits FROM ( -- Read Elements From Semantic Model 'visits_source' SELECT @@ -106,310 +172,143 @@ 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_0 - ) subq_1 - ) subq_2 - WHERE visit__referrer_id = 'ref_id_01' - ) subq_3 - GROUP BY - subq_3.metric_time__day - , subq_3.visit__referrer_id - ) subq_4 - FULL OUTER JOIN ( - -- Aggregate Measures - SELECT - subq_13.metric_time__day - , subq_13.visit__referrer_id - , SUM(subq_13.buys) AS buys - FROM ( - -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] - SELECT - subq_12.metric_time__day - , subq_12.visit__referrer_id - , subq_12.buys - FROM ( - -- Find conversions for user within the range of INF - SELECT - subq_11.ds__day - , subq_11.metric_time__day - , subq_11.user - , subq_11.visit__referrer_id - , subq_11.buys - , subq_11.visits - FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_7.visits) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_7.visit__referrer_id) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visit__referrer_id - , FIRST_VALUE(subq_7.ds__day) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_7.metric_time__day) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS metric_time__day - , FIRST_VALUE(subq_7.user) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_10.mf_internal_uuid AS mf_internal_uuid - , subq_10.buys AS buys + ) subq_4 + ) subq_5 + INNER JOIN ( + -- Add column with generated UUID + 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.buy__ds__day + , subq_7.buy__ds__week + , subq_7.buy__ds__month + , subq_7.buy__ds__quarter + , subq_7.buy__ds__year + , subq_7.buy__ds__extract_year + , subq_7.buy__ds__extract_quarter + , subq_7.buy__ds__extract_month + , subq_7.buy__ds__extract_day + , subq_7.buy__ds__extract_dow + , subq_7.buy__ds__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.user + , subq_7.session_id + , subq_7.buy__user + , subq_7.buy__session_id + , subq_7.buys + , subq_7.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_6.ds__day - , subq_6.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.buy__ds__day + , subq_6.buy__ds__week + , subq_6.buy__ds__month + , subq_6.buy__ds__quarter + , subq_6.buy__ds__year + , subq_6.buy__ds__extract_year + , subq_6.buy__ds__extract_quarter + , subq_6.buy__ds__extract_month + , subq_6.buy__ds__extract_day + , subq_6.buy__ds__extract_dow + , subq_6.buy__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy , subq_6.user - , subq_6.visit__referrer_id - , subq_6.visits + , subq_6.session_id + , subq_6.buy__user + , subq_6.buy__session_id + , subq_6.buys + , subq_6.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.visit__ds__day - , subq_5.visit__ds__week - , subq_5.visit__ds__month - , subq_5.visit__ds__quarter - , subq_5.visit__ds__year - , subq_5.visit__ds__extract_year - , subq_5.visit__ds__extract_quarter - , subq_5.visit__ds__extract_month - , subq_5.visit__ds__extract_day - , subq_5.visit__ds__extract_dow - , subq_5.visit__ds__extract_doy - , subq_5.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.user - , subq_5.session - , subq_5.visit__user - , subq_5.visit__session - , subq_5.referrer_id - , subq_5.visit__referrer_id - , subq_5.visits - , subq_5.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_5 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_6 ) subq_7 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_9.ds__day - , subq_9.ds__week - , subq_9.ds__month - , subq_9.ds__quarter - , subq_9.ds__year - , subq_9.ds__extract_year - , subq_9.ds__extract_quarter - , subq_9.ds__extract_month - , subq_9.ds__extract_day - , subq_9.ds__extract_dow - , subq_9.ds__extract_doy - , subq_9.buy__ds__day - , subq_9.buy__ds__week - , subq_9.buy__ds__month - , subq_9.buy__ds__quarter - , subq_9.buy__ds__year - , subq_9.buy__ds__extract_year - , subq_9.buy__ds__extract_quarter - , subq_9.buy__ds__extract_month - , subq_9.buy__ds__extract_day - , subq_9.buy__ds__extract_dow - , subq_9.buy__ds__extract_doy - , subq_9.metric_time__day - , subq_9.metric_time__week - , subq_9.metric_time__month - , subq_9.metric_time__quarter - , subq_9.metric_time__year - , subq_9.metric_time__extract_year - , subq_9.metric_time__extract_quarter - , subq_9.metric_time__extract_month - , subq_9.metric_time__extract_day - , subq_9.metric_time__extract_dow - , subq_9.metric_time__extract_doy - , subq_9.user - , subq_9.session_id - , subq_9.buy__user - , subq_9.buy__session_id - , subq_9.buys - , subq_9.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.buy__ds__day - , subq_8.buy__ds__week - , subq_8.buy__ds__month - , subq_8.buy__ds__quarter - , subq_8.buy__ds__year - , subq_8.buy__ds__extract_year - , subq_8.buy__ds__extract_quarter - , subq_8.buy__ds__extract_month - , subq_8.buy__ds__extract_day - , subq_8.buy__ds__extract_dow - , subq_8.buy__ds__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.user - , subq_8.session_id - , subq_8.buy__user - , subq_8.buy__session_id - , subq_8.buys - , subq_8.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 - ON - ( - subq_7.user = subq_10.user - ) AND ( - (subq_7.ds__day <= subq_10.ds__day) - ) - ) subq_11 - ) subq_12 - ) subq_13 + ) subq_8 + ON + (subq_5.user = subq_8.user) AND ((subq_5.ds__day <= subq_8.ds__day)) + ) subq_9 + ) subq_10 GROUP BY - subq_13.metric_time__day - , subq_13.visit__referrer_id - ) subq_14 + subq_10.metric_time__day + , subq_10.visit__referrer_id + ) subq_11 ON ( - subq_4.visit__referrer_id = subq_14.visit__referrer_id + subq_3.visit__referrer_id = subq_11.visit__referrer_id ) AND ( - subq_4.metric_time__day = subq_14.metric_time__day + subq_3.metric_time__day = subq_11.metric_time__day ) GROUP BY - COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) - , COALESCE(subq_4.visit__referrer_id, subq_14.visit__referrer_id) -) subq_15 + COALESCE(subq_3.metric_time__day, subq_11.metric_time__day) + , COALESCE(subq_3.visit__referrer_id, subq_11.visit__referrer_id) +) subq_12 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0_optimized.sql index 6c179cce7f..d744ea6452 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_categorical_filter__plan0_optimized.sql @@ -6,10 +6,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) AS visit__referrer_id - , MAX(subq_20.visits) AS visits - , MAX(subq_30.buys) AS buys + COALESCE(subq_16.metric_time__day, subq_24.metric_time__day) AS metric_time__day + , COALESCE(subq_16.visit__referrer_id, subq_24.visit__referrer_id) AS visit__referrer_id + , MAX(subq_16.visits) AS visits + , MAX(subq_24.buys) AS buys FROM ( -- Constrain Output with WHERE -- Aggregate Measures @@ -26,12 +26,12 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_18 + ) subq_14 WHERE visit__referrer_id = 'ref_id_01' GROUP BY metric_time__day , visit__referrer_id - ) subq_20 + ) subq_16 FULL OUTER JOIN ( -- Find conversions for user within the range of INF -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] @@ -43,48 +43,48 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_23.visits) OVER ( + FIRST_VALUE(subq_18.visits) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_23.visit__referrer_id) OVER ( + , FIRST_VALUE(subq_18.visit__referrer_id) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visit__referrer_id - , FIRST_VALUE(subq_23.ds__day) OVER ( + , FIRST_VALUE(subq_18.ds__day) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_23.metric_time__day) OVER ( + , FIRST_VALUE(subq_18.metric_time__day) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_23.user) OVER ( + , FIRST_VALUE(subq_18.user) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_26.mf_internal_uuid AS mf_internal_uuid - , subq_26.buys AS buys + , subq_21.mf_internal_uuid AS mf_internal_uuid + , subq_21.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -96,7 +96,7 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_23 + ) subq_18 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -107,25 +107,25 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_26 + ) subq_21 ON ( - subq_23.user = subq_26.user + subq_18.user = subq_21.user ) AND ( - (subq_23.ds__day <= subq_26.ds__day) + (subq_18.ds__day <= subq_21.ds__day) ) - ) subq_27 + ) subq_22 GROUP BY metric_time__day , visit__referrer_id - ) subq_30 + ) subq_24 ON ( - subq_20.visit__referrer_id = subq_30.visit__referrer_id + subq_16.visit__referrer_id = subq_24.visit__referrer_id ) AND ( - subq_20.metric_time__day = subq_30.metric_time__day + subq_16.metric_time__day = subq_24.metric_time__day ) GROUP BY - COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) - , COALESCE(subq_20.visit__referrer_id, subq_30.visit__referrer_id) -) subq_31 + COALESCE(subq_16.metric_time__day, subq_24.metric_time__day) + , COALESCE(subq_16.visit__referrer_id, subq_24.visit__referrer_id) +) subq_25 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0.sql index b1e85e150b..0a8c7c2eb9 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0.sql @@ -1,116 +1,216 @@ -- Compute Metrics via Expressions SELECT - subq_17.visit__referrer_id - , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate + subq_14.visit__referrer_id + , CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id - , MAX(subq_5.visits) AS visits - , MAX(subq_16.buys) AS buys + COALESCE(subq_4.visit__referrer_id, subq_13.visit__referrer_id) AS visit__referrer_id + , MAX(subq_4.visits) AS visits + , MAX(subq_13.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_4.visit__referrer_id - , SUM(subq_4.visits) AS visits + subq_3.visit__referrer_id + , SUM(subq_3.visits) AS visits FROM ( -- Constrain Output with WHERE SELECT - subq_3.visit__referrer_id - , subq_3.visits + subq_2.visit__referrer_id + , subq_2.visits FROM ( + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] -- Pass Only Elements: ['visits', 'visit__referrer_id'] SELECT - subq_2.visit__referrer_id - , subq_2.visits + subq_1.visit__referrer_id + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' + ) subq_2 + WHERE visit__referrer_id = 'ref_id_01' + ) subq_3 + GROUP BY + subq_3.visit__referrer_id + ) subq_4 + FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_12.visit__referrer_id + , SUM(subq_12.buys) AS buys + FROM ( + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys', 'visit__referrer_id'] + SELECT + subq_11.visit__referrer_id + , subq_11.buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_7.visits) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_7.visit__referrer_id) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visit__referrer_id + , FIRST_VALUE(subq_7.ds__day) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_7.user) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_10.mf_internal_uuid AS mf_internal_uuid + , subq_10.buys AS buys FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] + -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user'] SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.visit__ds__day - , subq_1.visit__ds__week - , subq_1.visit__ds__month - , subq_1.visit__ds__quarter - , subq_1.visit__ds__year - , subq_1.visit__ds__extract_year - , subq_1.visit__ds__extract_quarter - , subq_1.visit__ds__extract_month - , subq_1.visit__ds__extract_day - , subq_1.visit__ds__extract_dow - , subq_1.visit__ds__extract_doy - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.user - , subq_1.session - , subq_1.visit__user - , subq_1.visit__session - , subq_1.referrer_id - , subq_1.visit__referrer_id - , subq_1.visits - , subq_1.visitors + subq_6.ds__day + , subq_6.user + , subq_6.visit__referrer_id + , subq_6.visits FROM ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.visit__ds__day + , subq_5.visit__ds__week + , subq_5.visit__ds__month + , subq_5.visit__ds__quarter + , subq_5.visit__ds__year + , subq_5.visit__ds__extract_year + , subq_5.visit__ds__extract_quarter + , subq_5.visit__ds__extract_month + , subq_5.visit__ds__extract_day + , subq_5.visit__ds__extract_dow + , subq_5.visit__ds__extract_doy + , subq_5.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy + , subq_5.user + , subq_5.session + , subq_5.visit__user + , subq_5.visit__session + , subq_5.referrer_id + , subq_5.visit__referrer_id + , subq_5.visits + , subq_5.visitors FROM ( -- Read Elements From Semantic Model 'visits_source' SELECT @@ -145,339 +245,143 @@ 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_0 - ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' - ) subq_2 - ) subq_3 - WHERE visit__referrer_id = 'ref_id_01' - ) subq_4 - GROUP BY - subq_4.visit__referrer_id - ) subq_5 - FULL OUTER JOIN ( - -- Aggregate Measures - SELECT - subq_15.visit__referrer_id - , SUM(subq_15.buys) AS buys - FROM ( - -- Pass Only Elements: ['buys', 'visit__referrer_id'] - SELECT - subq_14.visit__referrer_id - , subq_14.buys - FROM ( - -- Find conversions for user within the range of INF - SELECT - subq_13.ds__day - , subq_13.user - , subq_13.visit__referrer_id - , subq_13.buys - , subq_13.visits - FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_9.visits) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_9.visit__referrer_id) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visit__referrer_id - , FIRST_VALUE(subq_9.ds__day) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_9.user) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_12.mf_internal_uuid AS mf_internal_uuid - , subq_12.buys AS buys + ) subq_5 + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' + ) subq_7 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.metric_time__day + , subq_9.metric_time__week + , subq_9.metric_time__month + , subq_9.metric_time__quarter + , subq_9.metric_time__year + , subq_9.metric_time__extract_year + , subq_9.metric_time__extract_quarter + , subq_9.metric_time__extract_month + , subq_9.metric_time__extract_day + , subq_9.metric_time__extract_dow + , subq_9.metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.buy__ds__day + , subq_8.buy__ds__week + , subq_8.buy__ds__month + , subq_8.buy__ds__quarter + , subq_8.buy__ds__year + , subq_8.buy__ds__extract_year + , subq_8.buy__ds__extract_quarter + , subq_8.buy__ds__extract_month + , subq_8.buy__ds__extract_day + , subq_8.buy__ds__extract_dow + , subq_8.buy__ds__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy , subq_8.user - , subq_8.visit__referrer_id - , subq_8.visits + , subq_8.session_id + , subq_8.buy__user + , subq_8.buy__session_id + , subq_8.buys + , subq_8.buyers FROM ( - -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] + -- Read Elements From Semantic Model 'buys_source' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.visit__ds__day - , subq_7.visit__ds__week - , subq_7.visit__ds__month - , subq_7.visit__ds__quarter - , subq_7.visit__ds__year - , subq_7.visit__ds__extract_year - , subq_7.visit__ds__extract_quarter - , subq_7.visit__ds__extract_month - , subq_7.visit__ds__extract_day - , subq_7.visit__ds__extract_dow - , subq_7.visit__ds__extract_doy - , subq_7.metric_time__day - , subq_7.metric_time__week - , subq_7.metric_time__month - , subq_7.metric_time__quarter - , subq_7.metric_time__year - , subq_7.metric_time__extract_year - , subq_7.metric_time__extract_quarter - , subq_7.metric_time__extract_month - , subq_7.metric_time__extract_day - , subq_7.metric_time__extract_dow - , subq_7.metric_time__extract_doy - , subq_7.user - , subq_7.session - , subq_7.visit__user - , subq_7.visit__session - , subq_7.referrer_id - , subq_7.visit__referrer_id - , subq_7.visits - , subq_7.visitors - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.visit__ds__day - , subq_6.visit__ds__week - , subq_6.visit__ds__month - , subq_6.visit__ds__quarter - , subq_6.visit__ds__year - , subq_6.visit__ds__extract_year - , subq_6.visit__ds__extract_quarter - , subq_6.visit__ds__extract_month - , subq_6.visit__ds__extract_day - , subq_6.visit__ds__extract_dow - , subq_6.visit__ds__extract_doy - , subq_6.ds__day AS metric_time__day - , subq_6.ds__week AS metric_time__week - , subq_6.ds__month AS metric_time__month - , subq_6.ds__quarter AS metric_time__quarter - , subq_6.ds__year AS metric_time__year - , subq_6.ds__extract_year AS metric_time__extract_year - , subq_6.ds__extract_quarter AS metric_time__extract_quarter - , subq_6.ds__extract_month AS metric_time__extract_month - , subq_6.ds__extract_day AS metric_time__extract_day - , subq_6.ds__extract_dow AS metric_time__extract_dow - , subq_6.ds__extract_doy AS metric_time__extract_doy - , subq_6.user - , subq_6.session - , subq_6.visit__user - , subq_6.visit__session - , subq_6.referrer_id - , subq_6.visit__referrer_id - , subq_6.visits - , subq_6.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_6 - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_8 ) subq_9 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_11.ds__day - , subq_11.ds__week - , subq_11.ds__month - , subq_11.ds__quarter - , subq_11.ds__year - , subq_11.ds__extract_year - , subq_11.ds__extract_quarter - , subq_11.ds__extract_month - , subq_11.ds__extract_day - , subq_11.ds__extract_dow - , subq_11.ds__extract_doy - , subq_11.buy__ds__day - , subq_11.buy__ds__week - , subq_11.buy__ds__month - , subq_11.buy__ds__quarter - , subq_11.buy__ds__year - , subq_11.buy__ds__extract_year - , subq_11.buy__ds__extract_quarter - , subq_11.buy__ds__extract_month - , subq_11.buy__ds__extract_day - , subq_11.buy__ds__extract_dow - , subq_11.buy__ds__extract_doy - , subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__month - , subq_11.metric_time__quarter - , subq_11.metric_time__year - , subq_11.metric_time__extract_year - , subq_11.metric_time__extract_quarter - , subq_11.metric_time__extract_month - , subq_11.metric_time__extract_day - , subq_11.metric_time__extract_dow - , subq_11.metric_time__extract_doy - , subq_11.user - , subq_11.session_id - , subq_11.buy__user - , subq_11.buy__session_id - , subq_11.buys - , subq_11.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.buy__ds__day - , subq_10.buy__ds__week - , subq_10.buy__ds__month - , subq_10.buy__ds__quarter - , subq_10.buy__ds__year - , subq_10.buy__ds__extract_year - , subq_10.buy__ds__extract_quarter - , subq_10.buy__ds__extract_month - , subq_10.buy__ds__extract_day - , subq_10.buy__ds__extract_dow - , subq_10.buy__ds__extract_doy - , subq_10.ds__day AS metric_time__day - , subq_10.ds__week AS metric_time__week - , subq_10.ds__month AS metric_time__month - , subq_10.ds__quarter AS metric_time__quarter - , subq_10.ds__year AS metric_time__year - , subq_10.ds__extract_year AS metric_time__extract_year - , subq_10.ds__extract_quarter AS metric_time__extract_quarter - , subq_10.ds__extract_month AS metric_time__extract_month - , subq_10.ds__extract_day AS metric_time__extract_day - , subq_10.ds__extract_dow AS metric_time__extract_dow - , subq_10.ds__extract_doy AS metric_time__extract_doy - , subq_10.user - , subq_10.session_id - , subq_10.buy__user - , subq_10.buy__session_id - , subq_10.buys - , subq_10.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_10 - ) subq_11 - ) subq_12 - ON - ( - subq_9.user = subq_12.user - ) AND ( - (subq_9.ds__day <= subq_12.ds__day) - ) - ) subq_13 - ) subq_14 - ) subq_15 + ) subq_10 + ON + ( + subq_7.user = subq_10.user + ) AND ( + (subq_7.ds__day <= subq_10.ds__day) + ) + ) subq_11 + ) subq_12 GROUP BY - subq_15.visit__referrer_id - ) subq_16 + subq_12.visit__referrer_id + ) subq_13 ON - subq_5.visit__referrer_id = subq_16.visit__referrer_id + subq_4.visit__referrer_id = subq_13.visit__referrer_id GROUP BY - COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) -) subq_17 + COALESCE(subq_4.visit__referrer_id, subq_13.visit__referrer_id) +) subq_14 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0_optimized.sql index 1269c6a617..a080413ede 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_time_constraint__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id - , MAX(subq_23.visits) AS visits - , MAX(subq_34.buys) AS buys + COALESCE(subq_19.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id + , MAX(subq_19.visits) AS visits + , MAX(subq_28.buys) AS buys FROM ( -- Constrain Output with WHERE -- Aggregate Measures @@ -24,11 +24,11 @@ FROM ( , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02' - ) subq_21 + ) subq_17 WHERE visit__referrer_id = 'ref_id_01' GROUP BY visit__referrer_id - ) subq_23 + ) subq_19 FULL OUTER JOIN ( -- Find conversions for user within the range of INF -- Pass Only Elements: ['buys', 'visit__referrer_id'] @@ -39,40 +39,40 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_27.visits) OVER ( + FIRST_VALUE(subq_22.visits) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_27.visit__referrer_id) OVER ( + , FIRST_VALUE(subq_22.visit__referrer_id) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visit__referrer_id - , FIRST_VALUE(subq_27.ds__day) OVER ( + , FIRST_VALUE(subq_22.ds__day) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_27.user) OVER ( + , FIRST_VALUE(subq_22.user) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_30.mf_internal_uuid AS mf_internal_uuid - , subq_30.buys AS buys + , subq_25.mf_internal_uuid AS mf_internal_uuid + , subq_25.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -85,7 +85,7 @@ FROM ( , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02' - ) subq_27 + ) subq_22 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -96,19 +96,19 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_30 + ) subq_25 ON ( - subq_27.user = subq_30.user + subq_22.user = subq_25.user ) AND ( - (subq_27.ds__day <= subq_30.ds__day) + (subq_22.ds__day <= subq_25.ds__day) ) - ) subq_31 + ) subq_26 GROUP BY visit__referrer_id - ) subq_34 + ) subq_28 ON - subq_23.visit__referrer_id = subq_34.visit__referrer_id + subq_19.visit__referrer_id = subq_28.visit__referrer_id GROUP BY - COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) -) subq_35 + COALESCE(subq_19.visit__referrer_id, subq_28.visit__referrer_id) +) subq_29 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0.sql index f4fe4a5c1a..4d276538f9 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0.sql @@ -1,72 +1,126 @@ -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day - , CAST(subq_15.buys AS DOUBLE) / CAST(NULLIF(subq_15.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days + subq_12.metric_time__day + , CAST(subq_12.buys AS DOUBLE) / CAST(NULLIF(subq_12.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) AS metric_time__day - , MAX(subq_4.visits) AS visits - , MAX(subq_14.buys) AS buys + COALESCE(subq_3.metric_time__day, subq_11.metric_time__day) AS metric_time__day + , MAX(subq_3.visits) AS visits + , MAX(subq_11.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , SUM(subq_3.visits) AS visits + subq_2.metric_time__day + , SUM(subq_2.visits) AS visits FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.visits + subq_1.metric_time__day + , subq_1.visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.visits + subq_0.ds__day AS metric_time__day + , subq_0.visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + WHERE metric_time__day = '2020-01-01' + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , SUM(subq_10.buys) AS buys + FROM ( + -- Find conversions for user within the range of 7 day + -- Pass Only Elements: ['buys', 'metric_time__day'] + SELECT + subq_9.metric_time__day + , subq_9.buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_5.visits) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_5.ds__day) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_5.metric_time__day) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_5.user) OVER ( + PARTITION BY + subq_8.user + , subq_8.ds__day + , subq_8.mf_internal_uuid + ORDER BY subq_5.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_8.mf_internal_uuid AS mf_internal_uuid + , subq_8.buys AS buys FROM ( -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors + subq_4.ds__day + , subq_4.ds__day AS metric_time__day + , subq_4.user + , subq_4.visits FROM ( -- Read Elements From Semantic Model 'visits_source' SELECT @@ -101,295 +155,145 @@ 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_0 - ) subq_1 - ) subq_2 - WHERE metric_time__day = '2020-01-01' - ) subq_3 - GROUP BY - subq_3.metric_time__day - ) subq_4 - FULL OUTER JOIN ( - -- Aggregate Measures - SELECT - subq_13.metric_time__day - , SUM(subq_13.buys) AS buys - FROM ( - -- Pass Only Elements: ['buys', 'metric_time__day'] - SELECT - subq_12.metric_time__day - , subq_12.buys - FROM ( - -- Find conversions for user within the range of 7 day - SELECT - subq_11.ds__day - , subq_11.metric_time__day - , subq_11.user - , subq_11.buys - , subq_11.visits - FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_7.visits) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_7.ds__day) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_7.metric_time__day) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS metric_time__day - , FIRST_VALUE(subq_7.user) OVER ( - PARTITION BY - subq_10.user - , subq_10.ds__day - , subq_10.mf_internal_uuid - ORDER BY subq_7.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_10.mf_internal_uuid AS mf_internal_uuid - , subq_10.buys AS buys + ) subq_4 + ) subq_5 + INNER JOIN ( + -- Add column with generated UUID + 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.buy__ds__day + , subq_7.buy__ds__week + , subq_7.buy__ds__month + , subq_7.buy__ds__quarter + , subq_7.buy__ds__year + , subq_7.buy__ds__extract_year + , subq_7.buy__ds__extract_quarter + , subq_7.buy__ds__extract_month + , subq_7.buy__ds__extract_day + , subq_7.buy__ds__extract_dow + , subq_7.buy__ds__extract_doy + , subq_7.metric_time__day + , subq_7.metric_time__week + , subq_7.metric_time__month + , subq_7.metric_time__quarter + , subq_7.metric_time__year + , subq_7.metric_time__extract_year + , subq_7.metric_time__extract_quarter + , subq_7.metric_time__extract_month + , subq_7.metric_time__extract_day + , subq_7.metric_time__extract_dow + , subq_7.metric_time__extract_doy + , subq_7.user + , subq_7.session_id + , subq_7.buy__user + , subq_7.buy__session_id + , subq_7.buys + , subq_7.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_6.ds__day - , subq_6.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.buy__ds__day + , subq_6.buy__ds__week + , subq_6.buy__ds__month + , subq_6.buy__ds__quarter + , subq_6.buy__ds__year + , subq_6.buy__ds__extract_year + , subq_6.buy__ds__extract_quarter + , subq_6.buy__ds__extract_month + , subq_6.buy__ds__extract_day + , subq_6.buy__ds__extract_dow + , subq_6.buy__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy , subq_6.user - , subq_6.visits + , subq_6.session_id + , subq_6.buy__user + , subq_6.buy__session_id + , subq_6.buys + , subq_6.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.visit__ds__day - , subq_5.visit__ds__week - , subq_5.visit__ds__month - , subq_5.visit__ds__quarter - , subq_5.visit__ds__year - , subq_5.visit__ds__extract_year - , subq_5.visit__ds__extract_quarter - , subq_5.visit__ds__extract_month - , subq_5.visit__ds__extract_day - , subq_5.visit__ds__extract_dow - , subq_5.visit__ds__extract_doy - , subq_5.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.user - , subq_5.session - , subq_5.visit__user - , subq_5.visit__session - , subq_5.referrer_id - , subq_5.visit__referrer_id - , subq_5.visits - , subq_5.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_5 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_6 ) subq_7 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_9.ds__day - , subq_9.ds__week - , subq_9.ds__month - , subq_9.ds__quarter - , subq_9.ds__year - , subq_9.ds__extract_year - , subq_9.ds__extract_quarter - , subq_9.ds__extract_month - , subq_9.ds__extract_day - , subq_9.ds__extract_dow - , subq_9.ds__extract_doy - , subq_9.buy__ds__day - , subq_9.buy__ds__week - , subq_9.buy__ds__month - , subq_9.buy__ds__quarter - , subq_9.buy__ds__year - , subq_9.buy__ds__extract_year - , subq_9.buy__ds__extract_quarter - , subq_9.buy__ds__extract_month - , subq_9.buy__ds__extract_day - , subq_9.buy__ds__extract_dow - , subq_9.buy__ds__extract_doy - , subq_9.metric_time__day - , subq_9.metric_time__week - , subq_9.metric_time__month - , subq_9.metric_time__quarter - , subq_9.metric_time__year - , subq_9.metric_time__extract_year - , subq_9.metric_time__extract_quarter - , subq_9.metric_time__extract_month - , subq_9.metric_time__extract_day - , subq_9.metric_time__extract_dow - , subq_9.metric_time__extract_doy - , subq_9.user - , subq_9.session_id - , subq_9.buy__user - , subq_9.buy__session_id - , subq_9.buys - , subq_9.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.buy__ds__day - , subq_8.buy__ds__week - , subq_8.buy__ds__month - , subq_8.buy__ds__quarter - , subq_8.buy__ds__year - , subq_8.buy__ds__extract_year - , subq_8.buy__ds__extract_quarter - , subq_8.buy__ds__extract_month - , subq_8.buy__ds__extract_day - , subq_8.buy__ds__extract_dow - , subq_8.buy__ds__extract_doy - , subq_8.ds__day AS metric_time__day - , subq_8.ds__week AS metric_time__week - , subq_8.ds__month AS metric_time__month - , subq_8.ds__quarter AS metric_time__quarter - , subq_8.ds__year AS metric_time__year - , subq_8.ds__extract_year AS metric_time__extract_year - , subq_8.ds__extract_quarter AS metric_time__extract_quarter - , subq_8.ds__extract_month AS metric_time__extract_month - , subq_8.ds__extract_day AS metric_time__extract_day - , subq_8.ds__extract_dow AS metric_time__extract_dow - , subq_8.ds__extract_doy AS metric_time__extract_doy - , subq_8.user - , subq_8.session_id - , subq_8.buy__user - , subq_8.buy__session_id - , subq_8.buys - , subq_8.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 - ON + ) subq_8 + ON + ( + subq_5.user = subq_8.user + ) AND ( ( - subq_7.user = subq_10.user + subq_5.ds__day <= subq_8.ds__day ) AND ( - ( - subq_7.ds__day <= subq_10.ds__day - ) AND ( - subq_7.ds__day > subq_10.ds__day - INTERVAL 7 day - ) + subq_5.ds__day > subq_8.ds__day - INTERVAL 7 day ) - ) subq_11 - ) subq_12 - ) subq_13 + ) + ) subq_9 + ) subq_10 GROUP BY - subq_13.metric_time__day - ) subq_14 + subq_10.metric_time__day + ) subq_11 ON - subq_4.metric_time__day = subq_14.metric_time__day + subq_3.metric_time__day = subq_11.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_3.metric_time__day, subq_11.metric_time__day) +) subq_12 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0_optimized.sql index 82f1fe235c..1612aae347 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , MAX(subq_20.visits) AS visits - , MAX(subq_30.buys) AS buys + COALESCE(subq_16.metric_time__day, subq_24.metric_time__day) AS metric_time__day + , MAX(subq_16.visits) AS visits + , MAX(subq_24.buys) AS buys FROM ( -- Constrain Output with WHERE -- Aggregate Measures @@ -22,11 +22,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_18 + ) subq_14 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__day - ) subq_20 + ) subq_16 FULL OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -37,40 +37,40 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_23.visits) OVER ( + FIRST_VALUE(subq_18.visits) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_23.ds__day) OVER ( + , FIRST_VALUE(subq_18.ds__day) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_23.metric_time__day) OVER ( + , FIRST_VALUE(subq_18.metric_time__day) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_23.user) OVER ( + , FIRST_VALUE(subq_18.user) OVER ( PARTITION BY - subq_26.user - , subq_26.ds__day - , subq_26.mf_internal_uuid - ORDER BY subq_23.ds__day DESC + subq_21.user + , subq_21.ds__day + , subq_21.mf_internal_uuid + ORDER BY subq_18.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_26.mf_internal_uuid AS mf_internal_uuid - , subq_26.buys AS buys + , subq_21.mf_internal_uuid AS mf_internal_uuid + , subq_21.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -81,7 +81,7 @@ FROM ( , user_id AS user , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_23 + ) subq_18 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -92,23 +92,23 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_26 + ) subq_21 ON ( - subq_23.user = subq_26.user + subq_18.user = subq_21.user ) AND ( ( - subq_23.ds__day <= subq_26.ds__day + subq_18.ds__day <= subq_21.ds__day ) AND ( - subq_23.ds__day > subq_26.ds__day - INTERVAL 7 day + subq_18.ds__day > subq_21.ds__day - INTERVAL 7 day ) ) - ) subq_27 + ) subq_22 GROUP BY metric_time__day - ) subq_30 + ) subq_24 ON - subq_20.metric_time__day = subq_30.metric_time__day + subq_16.metric_time__day = subq_24.metric_time__day GROUP BY - COALESCE(subq_20.metric_time__day, subq_30.metric_time__day) -) subq_31 + COALESCE(subq_16.metric_time__day, subq_24.metric_time__day) +) subq_25 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0.sql index d675fb6ad2..0028d87ee8 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0.sql @@ -1,121 +1,233 @@ -- Compute Metrics via Expressions SELECT - subq_17.metric_time__day - , subq_17.visit__referrer_id - , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days + subq_14.metric_time__day + , subq_14.visit__referrer_id + , CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day - , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) AS visit__referrer_id - , MAX(subq_5.visits) AS visits - , MAX(subq_16.buys) AS buys + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) AS metric_time__day + , COALESCE(subq_4.visit__referrer_id, subq_13.visit__referrer_id) AS visit__referrer_id + , MAX(subq_4.visits) AS visits + , MAX(subq_13.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , subq_4.visit__referrer_id - , SUM(subq_4.visits) AS visits + subq_3.metric_time__day + , subq_3.visit__referrer_id + , SUM(subq_3.visits) AS visits FROM ( -- Constrain Output with WHERE SELECT - subq_3.metric_time__day - , subq_3.visit__referrer_id - , subq_3.visits + subq_2.metric_time__day + , subq_2.visit__referrer_id + , subq_2.visits FROM ( + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] -- Pass Only Elements: ['visits', 'visit__referrer_id', 'metric_time__day'] SELECT - subq_2.metric_time__day - , subq_2.visit__referrer_id - , subq_2.visits + subq_1.metric_time__day + , subq_1.visit__referrer_id + , subq_1.visits + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.visit__ds__day + , subq_0.visit__ds__week + , subq_0.visit__ds__month + , subq_0.visit__ds__quarter + , subq_0.visit__ds__year + , subq_0.visit__ds__extract_year + , subq_0.visit__ds__extract_quarter + , subq_0.visit__ds__extract_month + , subq_0.visit__ds__extract_day + , subq_0.visit__ds__extract_dow + , subq_0.visit__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.session + , subq_0.visit__user + , subq_0.visit__session + , subq_0.referrer_id + , subq_0.visit__referrer_id + , subq_0.visits + , subq_0.visitors + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' + ) subq_2 + WHERE visit__referrer_id = 'ref_id_01' + ) subq_3 + GROUP BY + subq_3.metric_time__day + , subq_3.visit__referrer_id + ) subq_4 + FULL OUTER JOIN ( + -- Aggregate Measures + SELECT + subq_12.metric_time__day + , subq_12.visit__referrer_id + , SUM(subq_12.buys) AS buys + FROM ( + -- Find conversions for user within the range of 7 day + -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] + SELECT + subq_11.metric_time__day + , subq_11.visit__referrer_id + , subq_11.buys + FROM ( + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_7.visits) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_7.visit__referrer_id) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visit__referrer_id + , FIRST_VALUE(subq_7.ds__day) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_7.metric_time__day) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_7.user) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_10.mf_internal_uuid AS mf_internal_uuid + , subq_10.buys AS buys FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] + -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user'] SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.visit__ds__day - , subq_1.visit__ds__week - , subq_1.visit__ds__month - , subq_1.visit__ds__quarter - , subq_1.visit__ds__year - , subq_1.visit__ds__extract_year - , subq_1.visit__ds__extract_quarter - , subq_1.visit__ds__extract_month - , subq_1.visit__ds__extract_day - , subq_1.visit__ds__extract_dow - , subq_1.visit__ds__extract_doy - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.user - , subq_1.session - , subq_1.visit__user - , subq_1.visit__session - , subq_1.referrer_id - , subq_1.visit__referrer_id - , subq_1.visits - , subq_1.visitors + subq_6.ds__day + , subq_6.metric_time__day + , subq_6.user + , subq_6.visit__referrer_id + , subq_6.visits FROM ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors + subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.visit__ds__day + , subq_5.visit__ds__week + , subq_5.visit__ds__month + , subq_5.visit__ds__quarter + , subq_5.visit__ds__year + , subq_5.visit__ds__extract_year + , subq_5.visit__ds__extract_quarter + , subq_5.visit__ds__extract_month + , subq_5.visit__ds__extract_day + , subq_5.visit__ds__extract_dow + , subq_5.visit__ds__extract_doy + , subq_5.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy + , subq_5.user + , subq_5.session + , subq_5.visit__user + , subq_5.visit__session + , subq_5.referrer_id + , subq_5.visit__referrer_id + , subq_5.visits + , subq_5.visitors FROM ( -- Read Elements From Semantic Model 'visits_source' SELECT @@ -150,362 +262,153 @@ 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_0 - ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' - ) subq_2 - ) subq_3 - WHERE visit__referrer_id = 'ref_id_01' - ) subq_4 - GROUP BY - subq_4.metric_time__day - , subq_4.visit__referrer_id - ) subq_5 - FULL OUTER JOIN ( - -- Aggregate Measures - SELECT - subq_15.metric_time__day - , subq_15.visit__referrer_id - , SUM(subq_15.buys) AS buys - FROM ( - -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] - SELECT - subq_14.metric_time__day - , subq_14.visit__referrer_id - , subq_14.buys - FROM ( - -- Find conversions for user within the range of 7 day - SELECT - subq_13.ds__day - , subq_13.metric_time__day - , subq_13.user - , subq_13.visit__referrer_id - , subq_13.buys - , subq_13.visits - FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_9.visits) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_9.visit__referrer_id) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visit__referrer_id - , FIRST_VALUE(subq_9.ds__day) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_9.metric_time__day) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS metric_time__day - , FIRST_VALUE(subq_9.user) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_12.mf_internal_uuid AS mf_internal_uuid - , subq_12.buys AS buys + ) subq_5 + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' + ) subq_7 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.metric_time__day + , subq_9.metric_time__week + , subq_9.metric_time__month + , subq_9.metric_time__quarter + , subq_9.metric_time__year + , subq_9.metric_time__extract_year + , subq_9.metric_time__extract_quarter + , subq_9.metric_time__extract_month + , subq_9.metric_time__extract_day + , subq_9.metric_time__extract_dow + , subq_9.metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_8.ds__day - , subq_8.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.buy__ds__day + , subq_8.buy__ds__week + , subq_8.buy__ds__month + , subq_8.buy__ds__quarter + , subq_8.buy__ds__year + , subq_8.buy__ds__extract_year + , subq_8.buy__ds__extract_quarter + , subq_8.buy__ds__extract_month + , subq_8.buy__ds__extract_day + , subq_8.buy__ds__extract_dow + , subq_8.buy__ds__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy , subq_8.user - , subq_8.visit__referrer_id - , subq_8.visits + , subq_8.session_id + , subq_8.buy__user + , subq_8.buy__session_id + , subq_8.buys + , subq_8.buyers FROM ( - -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] + -- Read Elements From Semantic Model 'buys_source' SELECT - subq_7.ds__day - , subq_7.ds__week - , subq_7.ds__month - , subq_7.ds__quarter - , subq_7.ds__year - , subq_7.ds__extract_year - , subq_7.ds__extract_quarter - , subq_7.ds__extract_month - , subq_7.ds__extract_day - , subq_7.ds__extract_dow - , subq_7.ds__extract_doy - , subq_7.visit__ds__day - , subq_7.visit__ds__week - , subq_7.visit__ds__month - , subq_7.visit__ds__quarter - , subq_7.visit__ds__year - , subq_7.visit__ds__extract_year - , subq_7.visit__ds__extract_quarter - , subq_7.visit__ds__extract_month - , subq_7.visit__ds__extract_day - , subq_7.visit__ds__extract_dow - , subq_7.visit__ds__extract_doy - , subq_7.metric_time__day - , subq_7.metric_time__week - , subq_7.metric_time__month - , subq_7.metric_time__quarter - , subq_7.metric_time__year - , subq_7.metric_time__extract_year - , subq_7.metric_time__extract_quarter - , subq_7.metric_time__extract_month - , subq_7.metric_time__extract_day - , subq_7.metric_time__extract_dow - , subq_7.metric_time__extract_doy - , subq_7.user - , subq_7.session - , subq_7.visit__user - , subq_7.visit__session - , subq_7.referrer_id - , subq_7.visit__referrer_id - , subq_7.visits - , subq_7.visitors - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.visit__ds__day - , subq_6.visit__ds__week - , subq_6.visit__ds__month - , subq_6.visit__ds__quarter - , subq_6.visit__ds__year - , subq_6.visit__ds__extract_year - , subq_6.visit__ds__extract_quarter - , subq_6.visit__ds__extract_month - , subq_6.visit__ds__extract_day - , subq_6.visit__ds__extract_dow - , subq_6.visit__ds__extract_doy - , subq_6.ds__day AS metric_time__day - , subq_6.ds__week AS metric_time__week - , subq_6.ds__month AS metric_time__month - , subq_6.ds__quarter AS metric_time__quarter - , subq_6.ds__year AS metric_time__year - , subq_6.ds__extract_year AS metric_time__extract_year - , subq_6.ds__extract_quarter AS metric_time__extract_quarter - , subq_6.ds__extract_month AS metric_time__extract_month - , subq_6.ds__extract_day AS metric_time__extract_day - , subq_6.ds__extract_dow AS metric_time__extract_dow - , subq_6.ds__extract_doy AS metric_time__extract_doy - , subq_6.user - , subq_6.session - , subq_6.visit__user - , subq_6.visit__session - , subq_6.referrer_id - , subq_6.visit__referrer_id - , subq_6.visits - , subq_6.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_6 - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_8 ) subq_9 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_11.ds__day - , subq_11.ds__week - , subq_11.ds__month - , subq_11.ds__quarter - , subq_11.ds__year - , subq_11.ds__extract_year - , subq_11.ds__extract_quarter - , subq_11.ds__extract_month - , subq_11.ds__extract_day - , subq_11.ds__extract_dow - , subq_11.ds__extract_doy - , subq_11.buy__ds__day - , subq_11.buy__ds__week - , subq_11.buy__ds__month - , subq_11.buy__ds__quarter - , subq_11.buy__ds__year - , subq_11.buy__ds__extract_year - , subq_11.buy__ds__extract_quarter - , subq_11.buy__ds__extract_month - , subq_11.buy__ds__extract_day - , subq_11.buy__ds__extract_dow - , subq_11.buy__ds__extract_doy - , subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__month - , subq_11.metric_time__quarter - , subq_11.metric_time__year - , subq_11.metric_time__extract_year - , subq_11.metric_time__extract_quarter - , subq_11.metric_time__extract_month - , subq_11.metric_time__extract_day - , subq_11.metric_time__extract_dow - , subq_11.metric_time__extract_doy - , subq_11.user - , subq_11.session_id - , subq_11.buy__user - , subq_11.buy__session_id - , subq_11.buys - , subq_11.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.buy__ds__day - , subq_10.buy__ds__week - , subq_10.buy__ds__month - , subq_10.buy__ds__quarter - , subq_10.buy__ds__year - , subq_10.buy__ds__extract_year - , subq_10.buy__ds__extract_quarter - , subq_10.buy__ds__extract_month - , subq_10.buy__ds__extract_day - , subq_10.buy__ds__extract_dow - , subq_10.buy__ds__extract_doy - , subq_10.ds__day AS metric_time__day - , subq_10.ds__week AS metric_time__week - , subq_10.ds__month AS metric_time__month - , subq_10.ds__quarter AS metric_time__quarter - , subq_10.ds__year AS metric_time__year - , subq_10.ds__extract_year AS metric_time__extract_year - , subq_10.ds__extract_quarter AS metric_time__extract_quarter - , subq_10.ds__extract_month AS metric_time__extract_month - , subq_10.ds__extract_day AS metric_time__extract_day - , subq_10.ds__extract_dow AS metric_time__extract_dow - , subq_10.ds__extract_doy AS metric_time__extract_doy - , subq_10.user - , subq_10.session_id - , subq_10.buy__user - , subq_10.buy__session_id - , subq_10.buys - , subq_10.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_10 - ) subq_11 - ) subq_12 - ON + ) subq_10 + ON + ( + subq_7.user = subq_10.user + ) AND ( ( - subq_9.user = subq_12.user + subq_7.ds__day <= subq_10.ds__day ) AND ( - ( - subq_9.ds__day <= subq_12.ds__day - ) AND ( - subq_9.ds__day > subq_12.ds__day - INTERVAL 7 day - ) + subq_7.ds__day > subq_10.ds__day - INTERVAL 7 day ) - ) subq_13 - ) subq_14 - ) subq_15 + ) + ) subq_11 + ) subq_12 GROUP BY - subq_15.metric_time__day - , subq_15.visit__referrer_id - ) subq_16 + subq_12.metric_time__day + , subq_12.visit__referrer_id + ) subq_13 ON ( - subq_5.visit__referrer_id = subq_16.visit__referrer_id + subq_4.visit__referrer_id = subq_13.visit__referrer_id ) AND ( - subq_5.metric_time__day = subq_16.metric_time__day + subq_4.metric_time__day = subq_13.metric_time__day ) GROUP BY - COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) - , COALESCE(subq_5.visit__referrer_id, subq_16.visit__referrer_id) -) subq_17 + COALESCE(subq_4.metric_time__day, subq_13.metric_time__day) + , COALESCE(subq_4.visit__referrer_id, subq_13.visit__referrer_id) +) subq_14 diff --git a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql index 121a8a2629..ffe253052f 100644 --- a/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metric_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_with_window_and_time_constraint__plan0_optimized.sql @@ -6,10 +6,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day - , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) AS visit__referrer_id - , MAX(subq_23.visits) AS visits - , MAX(subq_34.buys) AS buys + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , COALESCE(subq_19.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id + , MAX(subq_19.visits) AS visits + , MAX(subq_28.buys) AS buys FROM ( -- Constrain Output with WHERE -- Aggregate Measures @@ -28,12 +28,12 @@ FROM ( , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02' - ) subq_21 + ) subq_17 WHERE visit__referrer_id = 'ref_id_01' GROUP BY metric_time__day , visit__referrer_id - ) subq_23 + ) subq_19 FULL OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] @@ -45,48 +45,48 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_27.visits) OVER ( + FIRST_VALUE(subq_22.visits) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_27.visit__referrer_id) OVER ( + , FIRST_VALUE(subq_22.visit__referrer_id) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visit__referrer_id - , FIRST_VALUE(subq_27.ds__day) OVER ( + , FIRST_VALUE(subq_22.ds__day) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_27.metric_time__day) OVER ( + , FIRST_VALUE(subq_22.metric_time__day) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_27.user) OVER ( + , FIRST_VALUE(subq_22.user) OVER ( PARTITION BY - subq_30.user - , subq_30.ds__day - , subq_30.mf_internal_uuid - ORDER BY subq_27.ds__day DESC + subq_25.user + , subq_25.ds__day + , subq_25.mf_internal_uuid + ORDER BY subq_22.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_30.mf_internal_uuid AS mf_internal_uuid - , subq_30.buys AS buys + , subq_25.mf_internal_uuid AS mf_internal_uuid + , subq_25.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -100,7 +100,7 @@ FROM ( , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-02' - ) subq_27 + ) subq_22 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -111,29 +111,29 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_30 + ) subq_25 ON ( - subq_27.user = subq_30.user + subq_22.user = subq_25.user ) AND ( ( - subq_27.ds__day <= subq_30.ds__day + subq_22.ds__day <= subq_25.ds__day ) AND ( - subq_27.ds__day > subq_30.ds__day - INTERVAL 7 day + subq_22.ds__day > subq_25.ds__day - INTERVAL 7 day ) ) - ) subq_31 + ) subq_26 GROUP BY metric_time__day , visit__referrer_id - ) subq_34 + ) subq_28 ON ( - subq_23.visit__referrer_id = subq_34.visit__referrer_id + subq_19.visit__referrer_id = subq_28.visit__referrer_id ) AND ( - subq_23.metric_time__day = subq_34.metric_time__day + subq_19.metric_time__day = subq_28.metric_time__day ) GROUP BY - COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) - , COALESCE(subq_23.visit__referrer_id, subq_34.visit__referrer_id) -) subq_35 + COALESCE(subq_19.metric_time__day, subq_28.metric_time__day) + , COALESCE(subq_19.visit__referrer_id, subq_28.visit__referrer_id) +) subq_29 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_count_with_no_group_by__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_count_with_no_group_by__plan0.sql index f422bff535..d91c9334e0 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_count_with_no_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_count_with_no_group_by__plan0.sql @@ -1,364 +1,269 @@ -- Compute Metrics via Expressions SELECT - subq_14.buys AS visit_buy_conversions + subq_11.buys AS visit_buy_conversions FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_3.visits) AS visits - , COALESCE(MAX(subq_13.buys), 0) AS buys + MAX(subq_2.visits) AS visits + , COALESCE(MAX(subq_10.buys), 0) AS buys FROM ( -- Aggregate Measures SELECT - SUM(subq_2.visits) AS visits + SUM(subq_1.visits) AS visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits',] SELECT - subq_1.visits + subq_0.visits FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 - ) subq_3 + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 CROSS JOIN ( -- Aggregate Measures SELECT - SUM(subq_12.buys) AS buys + SUM(subq_9.buys) AS buys FROM ( + -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys',] SELECT - subq_11.buys + subq_8.buys FROM ( - -- Find conversions for user within the range of 7 day - SELECT - subq_10.ds__day - , subq_10.user - , subq_10.buys - , subq_10.visits + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_4.visits) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_4.ds__day) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_4.user) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_7.mf_internal_uuid AS mf_internal_uuid + , subq_7.buys AS buys FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_6.visits) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_6.ds__day) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_6.user) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_9.mf_internal_uuid AS mf_internal_uuid - , subq_9.buys AS buys + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'user'] + SELECT + subq_3.ds__day + , subq_3.user + , subq_3.visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_3 + ) subq_4 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.buy__ds__day + , subq_6.buy__ds__week + , subq_6.buy__ds__month + , subq_6.buy__ds__quarter + , subq_6.buy__ds__year + , subq_6.buy__ds__extract_year + , subq_6.buy__ds__extract_quarter + , subq_6.buy__ds__extract_month + , subq_6.buy__ds__extract_day + , subq_6.buy__ds__extract_dow + , subq_6.buy__ds__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__week + , subq_6.metric_time__month + , subq_6.metric_time__quarter + , subq_6.metric_time__year + , subq_6.metric_time__extract_year + , subq_6.metric_time__extract_quarter + , subq_6.metric_time__extract_month + , subq_6.metric_time__extract_day + , subq_6.metric_time__extract_dow + , subq_6.metric_time__extract_doy + , subq_6.user + , subq_6.session_id + , subq_6.buy__user + , subq_6.buy__session_id + , subq_6.buys + , subq_6.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'ds__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.buy__ds__day + , subq_5.buy__ds__week + , subq_5.buy__ds__month + , subq_5.buy__ds__quarter + , subq_5.buy__ds__year + , subq_5.buy__ds__extract_year + , subq_5.buy__ds__extract_quarter + , subq_5.buy__ds__extract_month + , subq_5.buy__ds__extract_day + , subq_5.buy__ds__extract_dow + , subq_5.buy__ds__extract_doy + , subq_5.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy , subq_5.user - , subq_5.visits + , subq_5.session_id + , subq_5.buy__user + , subq_5.buy__session_id + , subq_5.buys + , subq_5.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' SELECT - 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.visit__ds__day - , subq_4.visit__ds__week - , subq_4.visit__ds__month - , subq_4.visit__ds__quarter - , subq_4.visit__ds__year - , subq_4.visit__ds__extract_year - , subq_4.visit__ds__extract_quarter - , subq_4.visit__ds__extract_month - , subq_4.visit__ds__extract_day - , subq_4.visit__ds__extract_dow - , subq_4.visit__ds__extract_doy - , subq_4.ds__day AS metric_time__day - , subq_4.ds__week AS metric_time__week - , subq_4.ds__month AS metric_time__month - , subq_4.ds__quarter AS metric_time__quarter - , subq_4.ds__year AS metric_time__year - , subq_4.ds__extract_year AS metric_time__extract_year - , subq_4.ds__extract_quarter AS metric_time__extract_quarter - , subq_4.ds__extract_month AS metric_time__extract_month - , subq_4.ds__extract_day AS metric_time__extract_day - , subq_4.ds__extract_dow AS metric_time__extract_dow - , subq_4.ds__extract_doy AS metric_time__extract_doy - , subq_4.user - , subq_4.session - , subq_4.visit__user - , subq_4.visit__session - , subq_4.referrer_id - , subq_4.visit__referrer_id - , subq_4.visits - , subq_4.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_4 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_5 ) subq_6 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.buy__ds__day - , subq_8.buy__ds__week - , subq_8.buy__ds__month - , subq_8.buy__ds__quarter - , subq_8.buy__ds__year - , subq_8.buy__ds__extract_year - , subq_8.buy__ds__extract_quarter - , subq_8.buy__ds__extract_month - , subq_8.buy__ds__extract_day - , subq_8.buy__ds__extract_dow - , subq_8.buy__ds__extract_doy - , subq_8.metric_time__day - , subq_8.metric_time__week - , subq_8.metric_time__month - , subq_8.metric_time__quarter - , subq_8.metric_time__year - , subq_8.metric_time__extract_year - , subq_8.metric_time__extract_quarter - , subq_8.metric_time__extract_month - , subq_8.metric_time__extract_day - , subq_8.metric_time__extract_dow - , subq_8.metric_time__extract_doy - , subq_8.user - , subq_8.session_id - , subq_8.buy__user - , subq_8.buy__session_id - , subq_8.buys - , subq_8.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - 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.buy__ds__day - , subq_7.buy__ds__week - , subq_7.buy__ds__month - , subq_7.buy__ds__quarter - , subq_7.buy__ds__year - , subq_7.buy__ds__extract_year - , subq_7.buy__ds__extract_quarter - , subq_7.buy__ds__extract_month - , subq_7.buy__ds__extract_day - , subq_7.buy__ds__extract_dow - , subq_7.buy__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_id - , subq_7.buy__user - , subq_7.buy__session_id - , subq_7.buys - , subq_7.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 - ON + ) subq_7 + ON + ( + subq_4.user = subq_7.user + ) AND ( ( - subq_6.user = subq_9.user + subq_4.ds__day <= subq_7.ds__day ) AND ( - ( - subq_6.ds__day <= subq_9.ds__day - ) AND ( - subq_6.ds__day > subq_9.ds__day - INTERVAL 7 day - ) + subq_4.ds__day > subq_7.ds__day - INTERVAL 7 day ) - ) subq_10 - ) subq_11 - ) subq_12 - ) subq_13 -) subq_14 + ) + ) subq_8 + ) subq_9 + ) subq_10 +) subq_11 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_count_with_no_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_count_with_no_group_by__plan0_optimized.sql index aa389bcb36..b05d8e3844 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_count_with_no_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_count_with_no_group_by__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Combine Aggregated Outputs -- Compute Metrics via Expressions SELECT - COALESCE(MAX(subq_28.buys), 0) AS visit_buy_conversions + COALESCE(MAX(subq_22.buys), 0) AS visit_buy_conversions FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -10,7 +10,7 @@ FROM ( SELECT SUM(1) AS visits FROM ***************************.fct_visits visits_source_src_28000 -) subq_18 +) subq_14 CROSS JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys',] @@ -20,32 +20,32 @@ CROSS JOIN ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_21.visits) OVER ( + FIRST_VALUE(subq_16.visits) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_21.ds__day) OVER ( + , FIRST_VALUE(subq_16.ds__day) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_21.user) OVER ( + , FIRST_VALUE(subq_16.user) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_24.mf_internal_uuid AS mf_internal_uuid - , subq_24.buys AS buys + , subq_19.mf_internal_uuid AS mf_internal_uuid + , subq_19.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -55,7 +55,7 @@ CROSS JOIN ( , user_id AS user , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_21 + ) subq_16 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -66,16 +66,16 @@ CROSS JOIN ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_24 + ) subq_19 ON ( - subq_21.user = subq_24.user + subq_16.user = subq_19.user ) AND ( ( - subq_21.ds__day <= subq_24.ds__day + subq_16.ds__day <= subq_19.ds__day ) AND ( - subq_21.ds__day > subq_24.ds__day - INTERVAL 7 day + subq_16.ds__day > subq_19.ds__day - INTERVAL 7 day ) ) - ) subq_25 -) subq_28 + ) subq_20 +) 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.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 7c2d19392d..dfa26ac33f 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 @@ -1,416 +1,320 @@ -- 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_17.metric_time__day + , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.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_5.metric_time__day, subq_16.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_5.visits), 0) AS visits + , COALESCE(MAX(subq_16.buys), 0) AS buys FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day - , subq_3.visits AS visits + subq_3.metric_time__day AS metric_time__day + , subq_2.visits AS visits FROM ( -- Time Spine SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_4.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_4 + ) subq_3 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.visits) AS visits + subq_1.metric_time__day + , SUM(subq_1.visits) AS visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.visits + subq_0.ds__day AS metric_time__day + , subq_0.visits FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 + subq_1.metric_time__day + ) subq_2 ON - subq_4.metric_time__day = subq_3.metric_time__day - ) subq_6 + subq_3.metric_time__day = subq_2.metric_time__day + ) subq_5 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - subq_17.metric_time__day AS metric_time__day - , subq_16.buys AS buys + subq_14.metric_time__day AS metric_time__day + , subq_13.buys AS buys FROM ( -- Time Spine SELECT - subq_18.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_18 - ) subq_17 + subq_15.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_15 + ) subq_14 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_15.metric_time__day - , SUM(subq_15.buys) AS buys + subq_12.metric_time__day + , SUM(subq_12.buys) AS buys FROM ( + -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] SELECT - subq_14.metric_time__day - , subq_14.buys + subq_11.metric_time__day + , subq_11.buys FROM ( - -- Find conversions for user within the range of 7 day - SELECT - subq_13.ds__day - , subq_13.metric_time__day - , subq_13.user - , subq_13.buys - , subq_13.visits + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_7.visits) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_7.ds__day) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_7.metric_time__day) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_7.user) OVER ( + PARTITION BY + subq_10.user + , subq_10.ds__day + , subq_10.mf_internal_uuid + ORDER BY subq_7.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_10.mf_internal_uuid AS mf_internal_uuid + , subq_10.buys AS buys FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_9.visits) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_9.ds__day) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_9.metric_time__day) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS metric_time__day - , FIRST_VALUE(subq_9.user) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_12.mf_internal_uuid AS mf_internal_uuid - , subq_12.buys AS buys + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_6.ds__day + , subq_6.ds__day AS metric_time__day + , subq_6.user + , subq_6.visits FROM ( - -- Pass Only Elements: ['visits', 'ds__day', 'metric_time__day', 'user'] + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_9.ds__day + , subq_9.ds__week + , subq_9.ds__month + , subq_9.ds__quarter + , subq_9.ds__year + , subq_9.ds__extract_year + , subq_9.ds__extract_quarter + , subq_9.ds__extract_month + , subq_9.ds__extract_day + , subq_9.ds__extract_dow + , subq_9.ds__extract_doy + , subq_9.buy__ds__day + , subq_9.buy__ds__week + , subq_9.buy__ds__month + , subq_9.buy__ds__quarter + , subq_9.buy__ds__year + , subq_9.buy__ds__extract_year + , subq_9.buy__ds__extract_quarter + , subq_9.buy__ds__extract_month + , subq_9.buy__ds__extract_day + , subq_9.buy__ds__extract_dow + , subq_9.buy__ds__extract_doy + , subq_9.metric_time__day + , subq_9.metric_time__week + , subq_9.metric_time__month + , subq_9.metric_time__quarter + , subq_9.metric_time__year + , subq_9.metric_time__extract_year + , subq_9.metric_time__extract_quarter + , subq_9.metric_time__extract_month + , subq_9.metric_time__extract_day + , subq_9.metric_time__extract_dow + , subq_9.metric_time__extract_doy + , subq_9.user + , subq_9.session_id + , subq_9.buy__user + , subq_9.buy__session_id + , subq_9.buys + , subq_9.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' SELECT subq_8.ds__day - , subq_8.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.buy__ds__day + , subq_8.buy__ds__week + , subq_8.buy__ds__month + , subq_8.buy__ds__quarter + , subq_8.buy__ds__year + , subq_8.buy__ds__extract_year + , subq_8.buy__ds__extract_quarter + , subq_8.buy__ds__extract_month + , subq_8.buy__ds__extract_day + , subq_8.buy__ds__extract_dow + , subq_8.buy__ds__extract_doy + , subq_8.ds__day AS metric_time__day + , subq_8.ds__week AS metric_time__week + , subq_8.ds__month AS metric_time__month + , subq_8.ds__quarter AS metric_time__quarter + , subq_8.ds__year AS metric_time__year + , subq_8.ds__extract_year AS metric_time__extract_year + , subq_8.ds__extract_quarter AS metric_time__extract_quarter + , subq_8.ds__extract_month AS metric_time__extract_month + , subq_8.ds__extract_day AS metric_time__extract_day + , subq_8.ds__extract_dow AS metric_time__extract_dow + , subq_8.ds__extract_doy AS metric_time__extract_doy , subq_8.user - , subq_8.visits + , subq_8.session_id + , subq_8.buy__user + , subq_8.buy__session_id + , subq_8.buys + , subq_8.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' 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 - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_7 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_8 ) subq_9 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_11.ds__day - , subq_11.ds__week - , subq_11.ds__month - , subq_11.ds__quarter - , subq_11.ds__year - , subq_11.ds__extract_year - , subq_11.ds__extract_quarter - , subq_11.ds__extract_month - , subq_11.ds__extract_day - , subq_11.ds__extract_dow - , subq_11.ds__extract_doy - , subq_11.buy__ds__day - , subq_11.buy__ds__week - , subq_11.buy__ds__month - , subq_11.buy__ds__quarter - , subq_11.buy__ds__year - , subq_11.buy__ds__extract_year - , subq_11.buy__ds__extract_quarter - , subq_11.buy__ds__extract_month - , subq_11.buy__ds__extract_day - , subq_11.buy__ds__extract_dow - , subq_11.buy__ds__extract_doy - , subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__month - , subq_11.metric_time__quarter - , subq_11.metric_time__year - , subq_11.metric_time__extract_year - , subq_11.metric_time__extract_quarter - , subq_11.metric_time__extract_month - , subq_11.metric_time__extract_day - , subq_11.metric_time__extract_dow - , subq_11.metric_time__extract_doy - , subq_11.user - , subq_11.session_id - , subq_11.buy__user - , subq_11.buy__session_id - , subq_11.buys - , subq_11.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.buy__ds__day - , subq_10.buy__ds__week - , subq_10.buy__ds__month - , subq_10.buy__ds__quarter - , subq_10.buy__ds__year - , subq_10.buy__ds__extract_year - , subq_10.buy__ds__extract_quarter - , subq_10.buy__ds__extract_month - , subq_10.buy__ds__extract_day - , subq_10.buy__ds__extract_dow - , subq_10.buy__ds__extract_doy - , subq_10.ds__day AS metric_time__day - , subq_10.ds__week AS metric_time__week - , subq_10.ds__month AS metric_time__month - , subq_10.ds__quarter AS metric_time__quarter - , subq_10.ds__year AS metric_time__year - , subq_10.ds__extract_year AS metric_time__extract_year - , subq_10.ds__extract_quarter AS metric_time__extract_quarter - , subq_10.ds__extract_month AS metric_time__extract_month - , subq_10.ds__extract_day AS metric_time__extract_day - , subq_10.ds__extract_dow AS metric_time__extract_dow - , subq_10.ds__extract_doy AS metric_time__extract_doy - , subq_10.user - , subq_10.session_id - , subq_10.buy__user - , subq_10.buy__session_id - , subq_10.buys - , subq_10.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_10 - ) subq_11 - ) subq_12 - ON + ) subq_10 + ON + ( + subq_7.user = subq_10.user + ) AND ( ( - subq_9.user = subq_12.user + subq_7.ds__day <= subq_10.ds__day ) AND ( - ( - subq_9.ds__day <= subq_12.ds__day - ) AND ( - subq_9.ds__day > subq_12.ds__day - INTERVAL 7 day - ) + subq_7.ds__day > subq_10.ds__day - INTERVAL 7 day ) - ) subq_13 - ) subq_14 - ) subq_15 + ) + ) subq_11 + ) subq_12 GROUP BY - subq_15.metric_time__day - ) subq_16 + subq_12.metric_time__day + ) subq_13 ON - subq_17.metric_time__day = subq_16.metric_time__day - ) subq_19 + subq_14.metric_time__day = subq_13.metric_time__day + ) subq_16 ON - subq_6.metric_time__day = subq_19.metric_time__day + subq_5.metric_time__day = subq_16.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_19.metric_time__day) -) subq_20 + COALESCE(subq_5.metric_time__day, subq_16.metric_time__day) +) subq_17 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 7f85edf1f7..dbcd9fe5ce 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 @@ -5,15 +5,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_27.metric_time__day, subq_40.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_27.visits), 0) AS visits - , COALESCE(MAX(subq_40.buys), 0) AS buys + COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_23.visits), 0) AS visits + , COALESCE(MAX(subq_34.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 + subq_22.ds AS metric_time__day + , subq_20.visits AS visits + FROM ***************************.mf_time_spine subq_22 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -27,19 +27,19 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_23 + ) subq_19 GROUP BY metric_time__day - ) subq_24 + ) subq_20 ON - subq_26.ds = subq_24.metric_time__day - ) subq_27 + subq_22.ds = subq_20.metric_time__day + ) subq_23 FULL OUTER JOIN ( -- Join to Time Spine Dataset SELECT - subq_39.ds AS metric_time__day - , subq_37.buys AS buys - FROM ***************************.mf_time_spine subq_39 + subq_33.ds AS metric_time__day + , subq_31.buys AS buys + FROM ***************************.mf_time_spine subq_33 LEFT OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'metric_time__day'] @@ -50,40 +50,40 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_30.visits) OVER ( + FIRST_VALUE(subq_25.visits) OVER ( PARTITION BY - subq_33.user - , subq_33.ds__day - , subq_33.mf_internal_uuid - ORDER BY subq_30.ds__day DESC + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_30.ds__day) OVER ( + , FIRST_VALUE(subq_25.ds__day) OVER ( PARTITION BY - subq_33.user - , subq_33.ds__day - , subq_33.mf_internal_uuid - ORDER BY subq_30.ds__day DESC + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_30.metric_time__day) OVER ( + , FIRST_VALUE(subq_25.metric_time__day) OVER ( PARTITION BY - subq_33.user - , subq_33.ds__day - , subq_33.mf_internal_uuid - ORDER BY subq_30.ds__day DESC + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_30.user) OVER ( + , FIRST_VALUE(subq_25.user) OVER ( PARTITION BY - subq_33.user - , subq_33.ds__day - , subq_33.mf_internal_uuid - ORDER BY subq_30.ds__day DESC + subq_28.user + , subq_28.ds__day + , subq_28.mf_internal_uuid + ORDER BY subq_25.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_33.mf_internal_uuid AS mf_internal_uuid - , subq_33.buys AS buys + , subq_28.mf_internal_uuid AS mf_internal_uuid + , subq_28.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -94,7 +94,7 @@ FROM ( , user_id AS user , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_30 + ) subq_25 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -105,26 +105,26 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_33 + ) subq_28 ON ( - subq_30.user = subq_33.user + subq_25.user = subq_28.user ) AND ( ( - subq_30.ds__day <= subq_33.ds__day + subq_25.ds__day <= subq_28.ds__day ) AND ( - subq_30.ds__day > subq_33.ds__day - INTERVAL 7 day + subq_25.ds__day > subq_28.ds__day - INTERVAL 7 day ) ) - ) subq_34 + ) subq_29 GROUP BY metric_time__day - ) subq_37 + ) subq_31 ON - subq_39.ds = subq_37.metric_time__day - ) subq_40 + subq_33.ds = subq_31.metric_time__day + ) subq_34 ON - subq_27.metric_time__day = subq_40.metric_time__day + subq_23.metric_time__day = subq_34.metric_time__day GROUP BY - COALESCE(subq_27.metric_time__day, subq_40.metric_time__day) -) subq_41 + COALESCE(subq_23.metric_time__day, subq_34.metric_time__day) +) subq_35 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate__plan0.sql index 8aa15de352..cd5d58ba6a 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate__plan0.sql @@ -1,380 +1,284 @@ -- Compute Metrics via Expressions SELECT - subq_14.visit__referrer_id - , CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate + subq_11.visit__referrer_id + , CAST(subq_11.buys AS DOUBLE) / CAST(NULLIF(subq_11.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) AS visit__referrer_id - , MAX(subq_3.visits) AS visits - , MAX(subq_13.buys) AS buys + COALESCE(subq_2.visit__referrer_id, subq_10.visit__referrer_id) AS visit__referrer_id + , MAX(subq_2.visits) AS visits + , MAX(subq_10.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_2.visit__referrer_id - , SUM(subq_2.visits) AS visits + subq_1.visit__referrer_id + , SUM(subq_1.visits) AS visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits', 'visit__referrer_id'] SELECT - subq_1.visit__referrer_id - , subq_1.visits + subq_0.visit__referrer_id + , subq_0.visits FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.visit__referrer_id - ) subq_3 + subq_1.visit__referrer_id + ) subq_2 FULL OUTER JOIN ( -- Aggregate Measures SELECT - subq_12.visit__referrer_id - , SUM(subq_12.buys) AS buys + subq_9.visit__referrer_id + , SUM(subq_9.buys) AS buys FROM ( + -- Find conversions for user within the range of INF -- Pass Only Elements: ['buys', 'visit__referrer_id'] SELECT - subq_11.visit__referrer_id - , subq_11.buys + subq_8.visit__referrer_id + , subq_8.buys FROM ( - -- Find conversions for user within the range of INF - SELECT - subq_10.ds__day - , subq_10.user - , subq_10.visit__referrer_id - , subq_10.buys - , subq_10.visits + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_4.visits) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_4.visit__referrer_id) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visit__referrer_id + , FIRST_VALUE(subq_4.ds__day) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_4.user) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_7.mf_internal_uuid AS mf_internal_uuid + , subq_7.buys AS buys FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_6.visits) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_6.visit__referrer_id) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visit__referrer_id - , FIRST_VALUE(subq_6.ds__day) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_6.user) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_9.mf_internal_uuid AS mf_internal_uuid - , subq_9.buys AS buys + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user'] + SELECT + subq_3.ds__day + , subq_3.user + , subq_3.visit__referrer_id + , subq_3.visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_3 + ) subq_4 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.buy__ds__day + , subq_6.buy__ds__week + , subq_6.buy__ds__month + , subq_6.buy__ds__quarter + , subq_6.buy__ds__year + , subq_6.buy__ds__extract_year + , subq_6.buy__ds__extract_quarter + , subq_6.buy__ds__extract_month + , subq_6.buy__ds__extract_day + , subq_6.buy__ds__extract_dow + , subq_6.buy__ds__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__week + , subq_6.metric_time__month + , subq_6.metric_time__quarter + , subq_6.metric_time__year + , subq_6.metric_time__extract_year + , subq_6.metric_time__extract_quarter + , subq_6.metric_time__extract_month + , subq_6.metric_time__extract_day + , subq_6.metric_time__extract_dow + , subq_6.metric_time__extract_doy + , subq_6.user + , subq_6.session_id + , subq_6.buy__user + , subq_6.buy__session_id + , subq_6.buys + , subq_6.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.buy__ds__day + , subq_5.buy__ds__week + , subq_5.buy__ds__month + , subq_5.buy__ds__quarter + , subq_5.buy__ds__year + , subq_5.buy__ds__extract_year + , subq_5.buy__ds__extract_quarter + , subq_5.buy__ds__extract_month + , subq_5.buy__ds__extract_day + , subq_5.buy__ds__extract_dow + , subq_5.buy__ds__extract_doy + , subq_5.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy , subq_5.user - , subq_5.visit__referrer_id - , subq_5.visits + , subq_5.session_id + , subq_5.buy__user + , subq_5.buy__session_id + , subq_5.buys + , subq_5.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' SELECT - 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.visit__ds__day - , subq_4.visit__ds__week - , subq_4.visit__ds__month - , subq_4.visit__ds__quarter - , subq_4.visit__ds__year - , subq_4.visit__ds__extract_year - , subq_4.visit__ds__extract_quarter - , subq_4.visit__ds__extract_month - , subq_4.visit__ds__extract_day - , subq_4.visit__ds__extract_dow - , subq_4.visit__ds__extract_doy - , subq_4.ds__day AS metric_time__day - , subq_4.ds__week AS metric_time__week - , subq_4.ds__month AS metric_time__month - , subq_4.ds__quarter AS metric_time__quarter - , subq_4.ds__year AS metric_time__year - , subq_4.ds__extract_year AS metric_time__extract_year - , subq_4.ds__extract_quarter AS metric_time__extract_quarter - , subq_4.ds__extract_month AS metric_time__extract_month - , subq_4.ds__extract_day AS metric_time__extract_day - , subq_4.ds__extract_dow AS metric_time__extract_dow - , subq_4.ds__extract_doy AS metric_time__extract_doy - , subq_4.user - , subq_4.session - , subq_4.visit__user - , subq_4.visit__session - , subq_4.referrer_id - , subq_4.visit__referrer_id - , subq_4.visits - , subq_4.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_4 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_5 ) subq_6 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.buy__ds__day - , subq_8.buy__ds__week - , subq_8.buy__ds__month - , subq_8.buy__ds__quarter - , subq_8.buy__ds__year - , subq_8.buy__ds__extract_year - , subq_8.buy__ds__extract_quarter - , subq_8.buy__ds__extract_month - , subq_8.buy__ds__extract_day - , subq_8.buy__ds__extract_dow - , subq_8.buy__ds__extract_doy - , subq_8.metric_time__day - , subq_8.metric_time__week - , subq_8.metric_time__month - , subq_8.metric_time__quarter - , subq_8.metric_time__year - , subq_8.metric_time__extract_year - , subq_8.metric_time__extract_quarter - , subq_8.metric_time__extract_month - , subq_8.metric_time__extract_day - , subq_8.metric_time__extract_dow - , subq_8.metric_time__extract_doy - , subq_8.user - , subq_8.session_id - , subq_8.buy__user - , subq_8.buy__session_id - , subq_8.buys - , subq_8.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - 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.buy__ds__day - , subq_7.buy__ds__week - , subq_7.buy__ds__month - , subq_7.buy__ds__quarter - , subq_7.buy__ds__year - , subq_7.buy__ds__extract_year - , subq_7.buy__ds__extract_quarter - , subq_7.buy__ds__extract_month - , subq_7.buy__ds__extract_day - , subq_7.buy__ds__extract_dow - , subq_7.buy__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_id - , subq_7.buy__user - , subq_7.buy__session_id - , subq_7.buys - , subq_7.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 - ON - (subq_6.user = subq_9.user) AND ((subq_6.ds__day <= subq_9.ds__day)) - ) subq_10 - ) subq_11 - ) subq_12 + ) subq_7 + ON + (subq_4.user = subq_7.user) AND ((subq_4.ds__day <= subq_7.ds__day)) + ) subq_8 + ) subq_9 GROUP BY - subq_12.visit__referrer_id - ) subq_13 + subq_9.visit__referrer_id + ) subq_10 ON - subq_3.visit__referrer_id = subq_13.visit__referrer_id + subq_2.visit__referrer_id = subq_10.visit__referrer_id GROUP BY - COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) -) subq_14 + COALESCE(subq_2.visit__referrer_id, subq_10.visit__referrer_id) +) subq_11 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate__plan0_optimized.sql index 6463cfb87c..20d4f449ae 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id - , MAX(subq_18.visits) AS visits - , MAX(subq_28.buys) AS buys + COALESCE(subq_14.visit__referrer_id, subq_22.visit__referrer_id) AS visit__referrer_id + , MAX(subq_14.visits) AS visits + , MAX(subq_22.buys) AS buys FROM ( -- Aggregate Measures SELECT @@ -21,10 +21,10 @@ FROM ( referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_17 + ) subq_13 GROUP BY visit__referrer_id - ) subq_18 + ) subq_14 FULL OUTER JOIN ( -- Find conversions for user within the range of INF -- Pass Only Elements: ['buys', 'visit__referrer_id'] @@ -35,40 +35,40 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_21.visits) OVER ( + FIRST_VALUE(subq_16.visits) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_21.visit__referrer_id) OVER ( + , FIRST_VALUE(subq_16.visit__referrer_id) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visit__referrer_id - , FIRST_VALUE(subq_21.ds__day) OVER ( + , FIRST_VALUE(subq_16.ds__day) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_21.user) OVER ( + , FIRST_VALUE(subq_16.user) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_24.mf_internal_uuid AS mf_internal_uuid - , subq_24.buys AS buys + , subq_19.mf_internal_uuid AS mf_internal_uuid + , subq_19.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -79,7 +79,7 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_21 + ) subq_16 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -90,19 +90,19 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_24 + ) subq_19 ON ( - subq_21.user = subq_24.user + subq_16.user = subq_19.user ) AND ( - (subq_21.ds__day <= subq_24.ds__day) + (subq_16.ds__day <= subq_19.ds__day) ) - ) subq_25 + ) subq_20 GROUP BY visit__referrer_id - ) subq_28 + ) subq_22 ON - subq_18.visit__referrer_id = subq_28.visit__referrer_id + subq_14.visit__referrer_id = subq_22.visit__referrer_id GROUP BY - COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) -) subq_29 + COALESCE(subq_14.visit__referrer_id, subq_22.visit__referrer_id) +) subq_23 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_constant_properties__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_constant_properties__plan0.sql index 08eba32e5f..6c1157d79d 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_constant_properties__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_constant_properties__plan0.sql @@ -1,429 +1,331 @@ -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day - , subq_14.visit__referrer_id - , CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_by_session + subq_11.metric_time__day + , subq_11.visit__referrer_id + , CAST(subq_11.buys AS DOUBLE) / CAST(NULLIF(subq_11.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_by_session FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_3.metric_time__day, subq_13.metric_time__day) AS metric_time__day - , COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) AS visit__referrer_id - , MAX(subq_3.visits) AS visits - , MAX(subq_13.buys) AS buys + COALESCE(subq_2.metric_time__day, subq_10.metric_time__day) AS metric_time__day + , COALESCE(subq_2.visit__referrer_id, subq_10.visit__referrer_id) AS visit__referrer_id + , MAX(subq_2.visits) AS visits + , MAX(subq_10.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , subq_2.visit__referrer_id - , SUM(subq_2.visits) AS visits + subq_1.metric_time__day + , subq_1.visit__referrer_id + , SUM(subq_1.visits) AS visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits', 'visit__referrer_id', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.visit__referrer_id - , subq_1.visits + subq_0.ds__day AS metric_time__day + , subq_0.visit__referrer_id + , subq_0.visits FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.metric_time__day - , subq_2.visit__referrer_id - ) subq_3 + subq_1.metric_time__day + , subq_1.visit__referrer_id + ) subq_2 FULL OUTER JOIN ( -- Aggregate Measures SELECT - subq_12.metric_time__day - , subq_12.visit__referrer_id - , SUM(subq_12.buys) AS buys + subq_9.metric_time__day + , subq_9.visit__referrer_id + , SUM(subq_9.buys) AS buys FROM ( + -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] SELECT - subq_11.metric_time__day - , subq_11.visit__referrer_id - , subq_11.buys + subq_8.metric_time__day + , subq_8.visit__referrer_id + , subq_8.buys FROM ( - -- Find conversions for user within the range of 7 day - SELECT - subq_10.ds__day - , subq_10.metric_time__day - , subq_10.user - , subq_10.session - , subq_10.visit__referrer_id - , subq_10.buys - , subq_10.visits + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_4.visits) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + , subq_7.session_id + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_4.visit__referrer_id) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + , subq_7.session_id + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visit__referrer_id + , FIRST_VALUE(subq_4.ds__day) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + , subq_7.session_id + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_4.metric_time__day) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + , subq_7.session_id + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_4.user) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + , subq_7.session_id + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , FIRST_VALUE(subq_4.session) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + , subq_7.session_id + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS session + , subq_7.mf_internal_uuid AS mf_internal_uuid + , subq_7.buys AS buys FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_6.visits) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - , subq_9.session_id - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_6.visit__referrer_id) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - , subq_9.session_id - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visit__referrer_id - , FIRST_VALUE(subq_6.ds__day) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - , subq_9.session_id - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_6.metric_time__day) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - , subq_9.session_id - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS metric_time__day - , FIRST_VALUE(subq_6.user) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - , subq_9.session_id - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , FIRST_VALUE(subq_6.session) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - , subq_9.session_id - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS session - , subq_9.mf_internal_uuid AS mf_internal_uuid - , subq_9.buys AS buys + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user', 'session'] + SELECT + subq_3.ds__day + , subq_3.ds__day AS metric_time__day + , subq_3.user + , subq_3.session + , subq_3.visit__referrer_id + , subq_3.visits FROM ( - -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user', 'session'] + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_3 + ) subq_4 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.buy__ds__day + , subq_6.buy__ds__week + , subq_6.buy__ds__month + , subq_6.buy__ds__quarter + , subq_6.buy__ds__year + , subq_6.buy__ds__extract_year + , subq_6.buy__ds__extract_quarter + , subq_6.buy__ds__extract_month + , subq_6.buy__ds__extract_day + , subq_6.buy__ds__extract_dow + , subq_6.buy__ds__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__week + , subq_6.metric_time__month + , subq_6.metric_time__quarter + , subq_6.metric_time__year + , subq_6.metric_time__extract_year + , subq_6.metric_time__extract_quarter + , subq_6.metric_time__extract_month + , subq_6.metric_time__extract_day + , subq_6.metric_time__extract_dow + , subq_6.metric_time__extract_doy + , subq_6.user + , subq_6.session_id + , subq_6.buy__user + , subq_6.buy__session_id + , subq_6.buys + , subq_6.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' SELECT subq_5.ds__day - , subq_5.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.buy__ds__day + , subq_5.buy__ds__week + , subq_5.buy__ds__month + , subq_5.buy__ds__quarter + , subq_5.buy__ds__year + , subq_5.buy__ds__extract_year + , subq_5.buy__ds__extract_quarter + , subq_5.buy__ds__extract_month + , subq_5.buy__ds__extract_day + , subq_5.buy__ds__extract_dow + , subq_5.buy__ds__extract_doy + , subq_5.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy , subq_5.user - , subq_5.session - , subq_5.visit__referrer_id - , subq_5.visits + , subq_5.session_id + , subq_5.buy__user + , subq_5.buy__session_id + , subq_5.buys + , subq_5.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' SELECT - 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.visit__ds__day - , subq_4.visit__ds__week - , subq_4.visit__ds__month - , subq_4.visit__ds__quarter - , subq_4.visit__ds__year - , subq_4.visit__ds__extract_year - , subq_4.visit__ds__extract_quarter - , subq_4.visit__ds__extract_month - , subq_4.visit__ds__extract_day - , subq_4.visit__ds__extract_dow - , subq_4.visit__ds__extract_doy - , subq_4.ds__day AS metric_time__day - , subq_4.ds__week AS metric_time__week - , subq_4.ds__month AS metric_time__month - , subq_4.ds__quarter AS metric_time__quarter - , subq_4.ds__year AS metric_time__year - , subq_4.ds__extract_year AS metric_time__extract_year - , subq_4.ds__extract_quarter AS metric_time__extract_quarter - , subq_4.ds__extract_month AS metric_time__extract_month - , subq_4.ds__extract_day AS metric_time__extract_day - , subq_4.ds__extract_dow AS metric_time__extract_dow - , subq_4.ds__extract_doy AS metric_time__extract_doy - , subq_4.user - , subq_4.session - , subq_4.visit__user - , subq_4.visit__session - , subq_4.referrer_id - , subq_4.visit__referrer_id - , subq_4.visits - , subq_4.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_4 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_5 ) subq_6 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.buy__ds__day - , subq_8.buy__ds__week - , subq_8.buy__ds__month - , subq_8.buy__ds__quarter - , subq_8.buy__ds__year - , subq_8.buy__ds__extract_year - , subq_8.buy__ds__extract_quarter - , subq_8.buy__ds__extract_month - , subq_8.buy__ds__extract_day - , subq_8.buy__ds__extract_dow - , subq_8.buy__ds__extract_doy - , subq_8.metric_time__day - , subq_8.metric_time__week - , subq_8.metric_time__month - , subq_8.metric_time__quarter - , subq_8.metric_time__year - , subq_8.metric_time__extract_year - , subq_8.metric_time__extract_quarter - , subq_8.metric_time__extract_month - , subq_8.metric_time__extract_day - , subq_8.metric_time__extract_dow - , subq_8.metric_time__extract_doy - , subq_8.user - , subq_8.session_id - , subq_8.buy__user - , subq_8.buy__session_id - , subq_8.buys - , subq_8.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - 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.buy__ds__day - , subq_7.buy__ds__week - , subq_7.buy__ds__month - , subq_7.buy__ds__quarter - , subq_7.buy__ds__year - , subq_7.buy__ds__extract_year - , subq_7.buy__ds__extract_quarter - , subq_7.buy__ds__extract_month - , subq_7.buy__ds__extract_day - , subq_7.buy__ds__extract_dow - , subq_7.buy__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_id - , subq_7.buy__user - , subq_7.buy__session_id - , subq_7.buys - , subq_7.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 - ON + ) subq_7 + ON + ( + subq_4.user = subq_7.user + ) AND ( + subq_4.session = subq_7.session_id + ) AND ( ( - subq_6.user = subq_9.user - ) AND ( - subq_6.session = subq_9.session_id + subq_4.ds__day <= subq_7.ds__day ) AND ( - ( - subq_6.ds__day <= subq_9.ds__day - ) AND ( - subq_6.ds__day > subq_9.ds__day - INTERVAL 7 day - ) + subq_4.ds__day > subq_7.ds__day - INTERVAL 7 day ) - ) subq_10 - ) subq_11 - ) subq_12 + ) + ) subq_8 + ) subq_9 GROUP BY - subq_12.metric_time__day - , subq_12.visit__referrer_id - ) subq_13 + subq_9.metric_time__day + , subq_9.visit__referrer_id + ) subq_10 ON ( - subq_3.visit__referrer_id = subq_13.visit__referrer_id + subq_2.visit__referrer_id = subq_10.visit__referrer_id ) AND ( - subq_3.metric_time__day = subq_13.metric_time__day + subq_2.metric_time__day = subq_10.metric_time__day ) GROUP BY - COALESCE(subq_3.metric_time__day, subq_13.metric_time__day) - , COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) -) subq_14 + COALESCE(subq_2.metric_time__day, subq_10.metric_time__day) + , COALESCE(subq_2.visit__referrer_id, subq_10.visit__referrer_id) +) subq_11 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_constant_properties__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_constant_properties__plan0_optimized.sql index 7edeea3bea..61635d3021 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_constant_properties__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_constant_properties__plan0_optimized.sql @@ -6,10 +6,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) AS metric_time__day - , COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id - , MAX(subq_18.visits) AS visits - , MAX(subq_28.buys) AS buys + COALESCE(subq_14.metric_time__day, subq_22.metric_time__day) AS metric_time__day + , COALESCE(subq_14.visit__referrer_id, subq_22.visit__referrer_id) AS visit__referrer_id + , MAX(subq_14.visits) AS visits + , MAX(subq_22.buys) AS buys FROM ( -- Aggregate Measures SELECT @@ -25,11 +25,11 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_17 + ) subq_13 GROUP BY metric_time__day , visit__referrer_id - ) subq_18 + ) subq_14 FULL OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] @@ -41,62 +41,62 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_21.visits) OVER ( + FIRST_VALUE(subq_16.visits) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - , subq_24.session_id - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + , subq_19.session_id + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_21.visit__referrer_id) OVER ( + , FIRST_VALUE(subq_16.visit__referrer_id) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - , subq_24.session_id - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + , subq_19.session_id + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visit__referrer_id - , FIRST_VALUE(subq_21.ds__day) OVER ( + , FIRST_VALUE(subq_16.ds__day) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - , subq_24.session_id - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + , subq_19.session_id + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_21.metric_time__day) OVER ( + , FIRST_VALUE(subq_16.metric_time__day) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - , subq_24.session_id - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + , subq_19.session_id + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_21.user) OVER ( + , FIRST_VALUE(subq_16.user) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - , subq_24.session_id - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + , subq_19.session_id + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , FIRST_VALUE(subq_21.session) OVER ( + , FIRST_VALUE(subq_16.session) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - , subq_24.session_id - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + , subq_19.session_id + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS session - , subq_24.mf_internal_uuid AS mf_internal_uuid - , subq_24.buys AS buys + , subq_19.mf_internal_uuid AS mf_internal_uuid + , subq_19.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -109,7 +109,7 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_21 + ) subq_16 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -121,31 +121,31 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_24 + ) subq_19 ON ( - subq_21.user = subq_24.user + subq_16.user = subq_19.user ) AND ( - subq_21.session = subq_24.session_id + subq_16.session = subq_19.session_id ) AND ( ( - subq_21.ds__day <= subq_24.ds__day + subq_16.ds__day <= subq_19.ds__day ) AND ( - subq_21.ds__day > subq_24.ds__day - INTERVAL 7 day + subq_16.ds__day > subq_19.ds__day - INTERVAL 7 day ) ) - ) subq_25 + ) subq_20 GROUP BY metric_time__day , visit__referrer_id - ) subq_28 + ) subq_22 ON ( - subq_18.visit__referrer_id = subq_28.visit__referrer_id + subq_14.visit__referrer_id = subq_22.visit__referrer_id ) AND ( - subq_18.metric_time__day = subq_28.metric_time__day + subq_14.metric_time__day = subq_22.metric_time__day ) GROUP BY - COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) - , COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) -) subq_29 + COALESCE(subq_14.metric_time__day, subq_22.metric_time__day) + , COALESCE(subq_14.visit__referrer_id, subq_22.visit__referrer_id) +) subq_23 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_no_group_by__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_no_group_by__plan0.sql index e435416417..3baeeed423 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_no_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_no_group_by__plan0.sql @@ -1,364 +1,269 @@ -- Compute Metrics via Expressions SELECT - CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days + CAST(subq_11.buys AS DOUBLE) / CAST(NULLIF(subq_11.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_3.visits) AS visits - , MAX(subq_13.buys) AS buys + MAX(subq_2.visits) AS visits + , MAX(subq_10.buys) AS buys FROM ( -- Aggregate Measures SELECT - SUM(subq_2.visits) AS visits + SUM(subq_1.visits) AS visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits',] SELECT - subq_1.visits + subq_0.visits FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 - ) subq_3 + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + ) subq_2 CROSS JOIN ( -- Aggregate Measures SELECT - SUM(subq_12.buys) AS buys + SUM(subq_9.buys) AS buys FROM ( + -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys',] SELECT - subq_11.buys + subq_8.buys FROM ( - -- Find conversions for user within the range of 7 day - SELECT - subq_10.ds__day - , subq_10.user - , subq_10.buys - , subq_10.visits + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_4.visits) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_4.ds__day) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_4.user) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_7.mf_internal_uuid AS mf_internal_uuid + , subq_7.buys AS buys FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_6.visits) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_6.ds__day) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_6.user) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_9.mf_internal_uuid AS mf_internal_uuid - , subq_9.buys AS buys + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'user'] + SELECT + subq_3.ds__day + , subq_3.user + , subq_3.visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_3 + ) subq_4 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.buy__ds__day + , subq_6.buy__ds__week + , subq_6.buy__ds__month + , subq_6.buy__ds__quarter + , subq_6.buy__ds__year + , subq_6.buy__ds__extract_year + , subq_6.buy__ds__extract_quarter + , subq_6.buy__ds__extract_month + , subq_6.buy__ds__extract_day + , subq_6.buy__ds__extract_dow + , subq_6.buy__ds__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__week + , subq_6.metric_time__month + , subq_6.metric_time__quarter + , subq_6.metric_time__year + , subq_6.metric_time__extract_year + , subq_6.metric_time__extract_quarter + , subq_6.metric_time__extract_month + , subq_6.metric_time__extract_day + , subq_6.metric_time__extract_dow + , subq_6.metric_time__extract_doy + , subq_6.user + , subq_6.session_id + , subq_6.buy__user + , subq_6.buy__session_id + , subq_6.buys + , subq_6.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'ds__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_5.ds__day + , subq_5.ds__week + , subq_5.ds__month + , subq_5.ds__quarter + , subq_5.ds__year + , subq_5.ds__extract_year + , subq_5.ds__extract_quarter + , subq_5.ds__extract_month + , subq_5.ds__extract_day + , subq_5.ds__extract_dow + , subq_5.ds__extract_doy + , subq_5.buy__ds__day + , subq_5.buy__ds__week + , subq_5.buy__ds__month + , subq_5.buy__ds__quarter + , subq_5.buy__ds__year + , subq_5.buy__ds__extract_year + , subq_5.buy__ds__extract_quarter + , subq_5.buy__ds__extract_month + , subq_5.buy__ds__extract_day + , subq_5.buy__ds__extract_dow + , subq_5.buy__ds__extract_doy + , subq_5.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy , subq_5.user - , subq_5.visits + , subq_5.session_id + , subq_5.buy__user + , subq_5.buy__session_id + , subq_5.buys + , subq_5.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' SELECT - 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.visit__ds__day - , subq_4.visit__ds__week - , subq_4.visit__ds__month - , subq_4.visit__ds__quarter - , subq_4.visit__ds__year - , subq_4.visit__ds__extract_year - , subq_4.visit__ds__extract_quarter - , subq_4.visit__ds__extract_month - , subq_4.visit__ds__extract_day - , subq_4.visit__ds__extract_dow - , subq_4.visit__ds__extract_doy - , subq_4.ds__day AS metric_time__day - , subq_4.ds__week AS metric_time__week - , subq_4.ds__month AS metric_time__month - , subq_4.ds__quarter AS metric_time__quarter - , subq_4.ds__year AS metric_time__year - , subq_4.ds__extract_year AS metric_time__extract_year - , subq_4.ds__extract_quarter AS metric_time__extract_quarter - , subq_4.ds__extract_month AS metric_time__extract_month - , subq_4.ds__extract_day AS metric_time__extract_day - , subq_4.ds__extract_dow AS metric_time__extract_dow - , subq_4.ds__extract_doy AS metric_time__extract_doy - , subq_4.user - , subq_4.session - , subq_4.visit__user - , subq_4.visit__session - , subq_4.referrer_id - , subq_4.visit__referrer_id - , subq_4.visits - , subq_4.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_4 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_5 ) subq_6 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.buy__ds__day - , subq_8.buy__ds__week - , subq_8.buy__ds__month - , subq_8.buy__ds__quarter - , subq_8.buy__ds__year - , subq_8.buy__ds__extract_year - , subq_8.buy__ds__extract_quarter - , subq_8.buy__ds__extract_month - , subq_8.buy__ds__extract_day - , subq_8.buy__ds__extract_dow - , subq_8.buy__ds__extract_doy - , subq_8.metric_time__day - , subq_8.metric_time__week - , subq_8.metric_time__month - , subq_8.metric_time__quarter - , subq_8.metric_time__year - , subq_8.metric_time__extract_year - , subq_8.metric_time__extract_quarter - , subq_8.metric_time__extract_month - , subq_8.metric_time__extract_day - , subq_8.metric_time__extract_dow - , subq_8.metric_time__extract_doy - , subq_8.user - , subq_8.session_id - , subq_8.buy__user - , subq_8.buy__session_id - , subq_8.buys - , subq_8.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - 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.buy__ds__day - , subq_7.buy__ds__week - , subq_7.buy__ds__month - , subq_7.buy__ds__quarter - , subq_7.buy__ds__year - , subq_7.buy__ds__extract_year - , subq_7.buy__ds__extract_quarter - , subq_7.buy__ds__extract_month - , subq_7.buy__ds__extract_day - , subq_7.buy__ds__extract_dow - , subq_7.buy__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_id - , subq_7.buy__user - , subq_7.buy__session_id - , subq_7.buys - , subq_7.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 - ON + ) subq_7 + ON + ( + subq_4.user = subq_7.user + ) AND ( ( - subq_6.user = subq_9.user + subq_4.ds__day <= subq_7.ds__day ) AND ( - ( - subq_6.ds__day <= subq_9.ds__day - ) AND ( - subq_6.ds__day > subq_9.ds__day - INTERVAL 7 day - ) + subq_4.ds__day > subq_7.ds__day - INTERVAL 7 day ) - ) subq_10 - ) subq_11 - ) subq_12 - ) subq_13 -) subq_14 + ) + ) subq_8 + ) subq_9 + ) subq_10 +) subq_11 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_no_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_no_group_by__plan0_optimized.sql index ca44562aee..6e00f76656 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_no_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_no_group_by__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Combine Aggregated Outputs -- Compute Metrics via Expressions SELECT - CAST(MAX(subq_28.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_18.visits), 0) AS DOUBLE) AS visit_buy_conversion_rate_7days + CAST(MAX(subq_22.buys) AS DOUBLE) / CAST(NULLIF(MAX(subq_14.visits), 0) AS DOUBLE) AS visit_buy_conversion_rate_7days FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -10,7 +10,7 @@ FROM ( SELECT SUM(1) AS visits FROM ***************************.fct_visits visits_source_src_28000 -) subq_18 +) subq_14 CROSS JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys',] @@ -20,32 +20,32 @@ CROSS JOIN ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_21.visits) OVER ( + FIRST_VALUE(subq_16.visits) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_21.ds__day) OVER ( + , FIRST_VALUE(subq_16.ds__day) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_21.user) OVER ( + , FIRST_VALUE(subq_16.user) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_24.mf_internal_uuid AS mf_internal_uuid - , subq_24.buys AS buys + , subq_19.mf_internal_uuid AS mf_internal_uuid + , subq_19.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -55,7 +55,7 @@ CROSS JOIN ( , user_id AS user , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_21 + ) subq_16 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -66,16 +66,16 @@ CROSS JOIN ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_24 + ) subq_19 ON ( - subq_21.user = subq_24.user + subq_16.user = subq_19.user ) AND ( ( - subq_21.ds__day <= subq_24.ds__day + subq_16.ds__day <= subq_19.ds__day ) AND ( - subq_21.ds__day > subq_24.ds__day - INTERVAL 7 day + subq_16.ds__day > subq_19.ds__day - INTERVAL 7 day ) ) - ) subq_25 -) subq_28 + ) subq_20 +) subq_22 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_window__plan0.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_window__plan0.sql index 66de5e3f1e..3f589c1525 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_window__plan0.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_window__plan0.sql @@ -1,411 +1,314 @@ -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day - , subq_14.visit__referrer_id - , CAST(subq_14.buys AS DOUBLE) / CAST(NULLIF(subq_14.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days + subq_11.metric_time__day + , subq_11.visit__referrer_id + , CAST(subq_11.buys AS DOUBLE) / CAST(NULLIF(subq_11.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_3.metric_time__day, subq_13.metric_time__day) AS metric_time__day - , COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) AS visit__referrer_id - , MAX(subq_3.visits) AS visits - , MAX(subq_13.buys) AS buys + COALESCE(subq_2.metric_time__day, subq_10.metric_time__day) AS metric_time__day + , COALESCE(subq_2.visit__referrer_id, subq_10.visit__referrer_id) AS visit__referrer_id + , MAX(subq_2.visits) AS visits + , MAX(subq_10.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , subq_2.visit__referrer_id - , SUM(subq_2.visits) AS visits + subq_1.metric_time__day + , subq_1.visit__referrer_id + , SUM(subq_1.visits) AS visits FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['visits', 'visit__referrer_id', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.visit__referrer_id - , subq_1.visits + subq_0.ds__day AS metric_time__day + , subq_0.visit__referrer_id + , subq_0.visits FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.metric_time__day - , subq_2.visit__referrer_id - ) subq_3 + subq_1.metric_time__day + , subq_1.visit__referrer_id + ) subq_2 FULL OUTER JOIN ( -- Aggregate Measures SELECT - subq_12.metric_time__day - , subq_12.visit__referrer_id - , SUM(subq_12.buys) AS buys + subq_9.metric_time__day + , subq_9.visit__referrer_id + , SUM(subq_9.buys) AS buys FROM ( + -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] SELECT - subq_11.metric_time__day - , subq_11.visit__referrer_id - , subq_11.buys + subq_8.metric_time__day + , subq_8.visit__referrer_id + , subq_8.buys FROM ( - -- Find conversions for user within the range of 7 day - SELECT - subq_10.ds__day - , subq_10.metric_time__day - , subq_10.user - , subq_10.visit__referrer_id - , subq_10.buys - , subq_10.visits + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_4.visits) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_4.visit__referrer_id) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visit__referrer_id + , FIRST_VALUE(subq_4.ds__day) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_4.metric_time__day) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_4.user) OVER ( + PARTITION BY + subq_7.user + , subq_7.ds__day + , subq_7.mf_internal_uuid + ORDER BY subq_4.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_7.mf_internal_uuid AS mf_internal_uuid + , subq_7.buys AS buys FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_6.visits) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_6.visit__referrer_id) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visit__referrer_id - , FIRST_VALUE(subq_6.ds__day) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_6.metric_time__day) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS metric_time__day - , FIRST_VALUE(subq_6.user) OVER ( - PARTITION BY - subq_9.user - , subq_9.ds__day - , subq_9.mf_internal_uuid - ORDER BY subq_6.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_9.mf_internal_uuid AS mf_internal_uuid - , subq_9.buys AS buys + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user'] + SELECT + subq_3.ds__day + , subq_3.ds__day AS metric_time__day + , subq_3.user + , subq_3.visit__referrer_id + , subq_3.visits + FROM ( + -- Read Elements From Semantic Model 'visits_source' + SELECT + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_3 + ) subq_4 + INNER JOIN ( + -- Add column with generated UUID + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.buy__ds__day + , subq_6.buy__ds__week + , subq_6.buy__ds__month + , subq_6.buy__ds__quarter + , subq_6.buy__ds__year + , subq_6.buy__ds__extract_year + , subq_6.buy__ds__extract_quarter + , subq_6.buy__ds__extract_month + , subq_6.buy__ds__extract_day + , subq_6.buy__ds__extract_dow + , subq_6.buy__ds__extract_doy + , subq_6.metric_time__day + , subq_6.metric_time__week + , subq_6.metric_time__month + , subq_6.metric_time__quarter + , subq_6.metric_time__year + , subq_6.metric_time__extract_year + , subq_6.metric_time__extract_quarter + , subq_6.metric_time__extract_month + , subq_6.metric_time__extract_day + , subq_6.metric_time__extract_dow + , subq_6.metric_time__extract_doy + , subq_6.user + , subq_6.session_id + , subq_6.buy__user + , subq_6.buy__session_id + , subq_6.buys + , subq_6.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['visits', 'visit__referrer_id', 'ds__day', 'metric_time__day', 'user'] + -- Metric Time Dimension 'ds' SELECT subq_5.ds__day - , subq_5.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.buy__ds__day + , subq_5.buy__ds__week + , subq_5.buy__ds__month + , subq_5.buy__ds__quarter + , subq_5.buy__ds__year + , subq_5.buy__ds__extract_year + , subq_5.buy__ds__extract_quarter + , subq_5.buy__ds__extract_month + , subq_5.buy__ds__extract_day + , subq_5.buy__ds__extract_dow + , subq_5.buy__ds__extract_doy + , subq_5.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy , subq_5.user - , subq_5.visit__referrer_id - , subq_5.visits + , subq_5.session_id + , subq_5.buy__user + , subq_5.buy__session_id + , subq_5.buys + , subq_5.buyers FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'buys_source' SELECT - 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.visit__ds__day - , subq_4.visit__ds__week - , subq_4.visit__ds__month - , subq_4.visit__ds__quarter - , subq_4.visit__ds__year - , subq_4.visit__ds__extract_year - , subq_4.visit__ds__extract_quarter - , subq_4.visit__ds__extract_month - , subq_4.visit__ds__extract_day - , subq_4.visit__ds__extract_dow - , subq_4.visit__ds__extract_doy - , subq_4.ds__day AS metric_time__day - , subq_4.ds__week AS metric_time__week - , subq_4.ds__month AS metric_time__month - , subq_4.ds__quarter AS metric_time__quarter - , subq_4.ds__year AS metric_time__year - , subq_4.ds__extract_year AS metric_time__extract_year - , subq_4.ds__extract_quarter AS metric_time__extract_quarter - , subq_4.ds__extract_month AS metric_time__extract_month - , subq_4.ds__extract_day AS metric_time__extract_day - , subq_4.ds__extract_dow AS metric_time__extract_dow - , subq_4.ds__extract_doy AS metric_time__extract_doy - , subq_4.user - , subq_4.session - , subq_4.visit__user - , subq_4.visit__session - , subq_4.referrer_id - , subq_4.visit__referrer_id - , subq_4.visits - , subq_4.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_4 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 ) subq_5 ) subq_6 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_8.ds__day - , subq_8.ds__week - , subq_8.ds__month - , subq_8.ds__quarter - , subq_8.ds__year - , subq_8.ds__extract_year - , subq_8.ds__extract_quarter - , subq_8.ds__extract_month - , subq_8.ds__extract_day - , subq_8.ds__extract_dow - , subq_8.ds__extract_doy - , subq_8.buy__ds__day - , subq_8.buy__ds__week - , subq_8.buy__ds__month - , subq_8.buy__ds__quarter - , subq_8.buy__ds__year - , subq_8.buy__ds__extract_year - , subq_8.buy__ds__extract_quarter - , subq_8.buy__ds__extract_month - , subq_8.buy__ds__extract_day - , subq_8.buy__ds__extract_dow - , subq_8.buy__ds__extract_doy - , subq_8.metric_time__day - , subq_8.metric_time__week - , subq_8.metric_time__month - , subq_8.metric_time__quarter - , subq_8.metric_time__year - , subq_8.metric_time__extract_year - , subq_8.metric_time__extract_quarter - , subq_8.metric_time__extract_month - , subq_8.metric_time__extract_day - , subq_8.metric_time__extract_dow - , subq_8.metric_time__extract_doy - , subq_8.user - , subq_8.session_id - , subq_8.buy__user - , subq_8.buy__session_id - , subq_8.buys - , subq_8.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - 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.buy__ds__day - , subq_7.buy__ds__week - , subq_7.buy__ds__month - , subq_7.buy__ds__quarter - , subq_7.buy__ds__year - , subq_7.buy__ds__extract_year - , subq_7.buy__ds__extract_quarter - , subq_7.buy__ds__extract_month - , subq_7.buy__ds__extract_day - , subq_7.buy__ds__extract_dow - , subq_7.buy__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_id - , subq_7.buy__user - , subq_7.buy__session_id - , subq_7.buys - , subq_7.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 - ON + ) subq_7 + ON + ( + subq_4.user = subq_7.user + ) AND ( ( - subq_6.user = subq_9.user + subq_4.ds__day <= subq_7.ds__day ) AND ( - ( - subq_6.ds__day <= subq_9.ds__day - ) AND ( - subq_6.ds__day > subq_9.ds__day - INTERVAL 7 day - ) + subq_4.ds__day > subq_7.ds__day - INTERVAL 7 day ) - ) subq_10 - ) subq_11 - ) subq_12 + ) + ) subq_8 + ) subq_9 GROUP BY - subq_12.metric_time__day - , subq_12.visit__referrer_id - ) subq_13 + subq_9.metric_time__day + , subq_9.visit__referrer_id + ) subq_10 ON ( - subq_3.visit__referrer_id = subq_13.visit__referrer_id + subq_2.visit__referrer_id = subq_10.visit__referrer_id ) AND ( - subq_3.metric_time__day = subq_13.metric_time__day + subq_2.metric_time__day = subq_10.metric_time__day ) GROUP BY - COALESCE(subq_3.metric_time__day, subq_13.metric_time__day) - , COALESCE(subq_3.visit__referrer_id, subq_13.visit__referrer_id) -) subq_14 + COALESCE(subq_2.metric_time__day, subq_10.metric_time__day) + , COALESCE(subq_2.visit__referrer_id, subq_10.visit__referrer_id) +) subq_11 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_window__plan0_optimized.sql index 68448ef816..25bddece36 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/DuckDB/test_conversion_rate_with_window__plan0_optimized.sql @@ -6,10 +6,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) AS metric_time__day - , COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) AS visit__referrer_id - , MAX(subq_18.visits) AS visits - , MAX(subq_28.buys) AS buys + COALESCE(subq_14.metric_time__day, subq_22.metric_time__day) AS metric_time__day + , COALESCE(subq_14.visit__referrer_id, subq_22.visit__referrer_id) AS visit__referrer_id + , MAX(subq_14.visits) AS visits + , MAX(subq_22.buys) AS buys FROM ( -- Aggregate Measures SELECT @@ -25,11 +25,11 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_17 + ) subq_13 GROUP BY metric_time__day , visit__referrer_id - ) subq_18 + ) subq_14 FULL OUTER JOIN ( -- Find conversions for user within the range of 7 day -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day'] @@ -41,48 +41,48 @@ FROM ( FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_21.visits) OVER ( + FIRST_VALUE(subq_16.visits) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_21.visit__referrer_id) OVER ( + , FIRST_VALUE(subq_16.visit__referrer_id) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visit__referrer_id - , FIRST_VALUE(subq_21.ds__day) OVER ( + , FIRST_VALUE(subq_16.ds__day) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_21.metric_time__day) OVER ( + , FIRST_VALUE(subq_16.metric_time__day) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_21.user) OVER ( + , FIRST_VALUE(subq_16.user) OVER ( PARTITION BY - subq_24.user - , subq_24.ds__day - , subq_24.mf_internal_uuid - ORDER BY subq_21.ds__day DESC + subq_19.user + , subq_19.ds__day + , subq_19.mf_internal_uuid + ORDER BY subq_16.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_24.mf_internal_uuid AS mf_internal_uuid - , subq_24.buys AS buys + , subq_19.mf_internal_uuid AS mf_internal_uuid + , subq_19.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -94,7 +94,7 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_21 + ) subq_16 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -105,29 +105,29 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_24 + ) subq_19 ON ( - subq_21.user = subq_24.user + subq_16.user = subq_19.user ) AND ( ( - subq_21.ds__day <= subq_24.ds__day + subq_16.ds__day <= subq_19.ds__day ) AND ( - subq_21.ds__day > subq_24.ds__day - INTERVAL 7 day + subq_16.ds__day > subq_19.ds__day - INTERVAL 7 day ) ) - ) subq_25 + ) subq_20 GROUP BY metric_time__day , visit__referrer_id - ) subq_28 + ) subq_22 ON ( - subq_18.visit__referrer_id = subq_28.visit__referrer_id + subq_14.visit__referrer_id = subq_22.visit__referrer_id ) AND ( - subq_18.metric_time__day = subq_28.metric_time__day + subq_14.metric_time__day = subq_22.metric_time__day ) GROUP BY - COALESCE(subq_18.metric_time__day, subq_28.metric_time__day) - , COALESCE(subq_18.visit__referrer_id, subq_28.visit__referrer_id) -) subq_29 + COALESCE(subq_14.metric_time__day, subq_22.metric_time__day) + , COALESCE(subq_14.visit__referrer_id, subq_22.visit__referrer_id) +) subq_23 diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_count_with_no_group_by__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_count_with_no_group_by__plan0.xml index 9b84078e53..e0f58cfa45 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_count_with_no_group_by__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_count_with_no_group_by__plan0.xml @@ -3,7 +3,7 @@ - + @@ -24,7 +24,7 @@ - + @@ -41,352 +41,155 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -402,64 +205,433 @@ - + + - - + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + @@ -468,950 +640,347 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + 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 12cae237f7..c60434ebd7 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 @@ -2,7 +2,7 @@ - + @@ -33,7 +33,7 @@ - + @@ -48,13 +48,13 @@ - - + + - + @@ -65,7 +65,7 @@ - + @@ -82,7 +82,7 @@ - + @@ -93,391 +93,177 @@ - + - + + - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -486,13 +272,13 @@ - - + + - + @@ -503,7 +289,7 @@ - + @@ -520,7 +306,7 @@ - + @@ -531,1053 +317,815 @@ - + - + + + - + - - + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + - - + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - + + + + + + + + + + - + - - - + + - + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate__plan0.xml index 76d275bfed..cfaa4faa2b 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate__plan0.xml @@ -3,7 +3,7 @@ - + @@ -31,7 +31,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -58,363 +58,167 @@ - + - + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -423,7 +227,7 @@ - + @@ -434,1043 +238,805 @@ - + - + + + - + - - + + - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - + + - + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_constant_properties__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_constant_properties__plan0.xml index 34cd8e1ee7..684b47de8d 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_constant_properties__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_constant_properties__plan0.xml @@ -2,9 +2,9 @@ - + - + @@ -40,7 +40,7 @@ - + @@ -60,10 +60,10 @@ - + - + @@ -73,371 +73,176 @@ - + - + - + + + - + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -445,10 +250,10 @@ - + - + @@ -458,1079 +263,834 @@ - + - + - + + + - + - + - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + - + - - + + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_no_group_by__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_no_group_by__plan0.xml index 5a9ccba69d..d96529a020 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_no_group_by__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_no_group_by__plan0.xml @@ -27,7 +27,7 @@ - + @@ -44,352 +44,155 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -405,64 +208,433 @@ - + + - - + + - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - + + @@ -471,950 +643,347 @@ - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_window__plan0.xml b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_window__plan0.xml index e622a820b3..71fb24565c 100644 --- a/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_window__plan0.xml +++ b/tests_metricflow/snapshots/test_conversion_metrics_to_sql.py/SqlQueryPlan/test_conversion_rate_with_window__plan0.xml @@ -2,9 +2,9 @@ - + - + @@ -40,7 +40,7 @@ - + @@ -60,10 +60,10 @@ - + - + @@ -73,371 +73,176 @@ - + - + - + + + - + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -445,10 +250,10 @@ - + - + @@ -458,1067 +263,824 @@ - + - + - + + + - + - + - - + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - + + + + + + + + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + - + - - - - + + - + - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql index 417d11e301..9baf1f0efb 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0.sql @@ -1,174 +1,135 @@ -- Re-aggregate Metric via Group By SELECT - subq_8.metric_time__week - , subq_8.metric_time__quarter - , subq_8.revenue_all_time + subq_7.metric_time__week + , subq_7.metric_time__quarter + , subq_7.revenue_all_time FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_7.metric_time__week - , subq_7.metric_time__quarter - , LAST_VALUE(subq_7.revenue_all_time) OVER ( + subq_6.metric_time__week + , subq_6.metric_time__quarter + , LAST_VALUE(subq_6.revenue_all_time) OVER ( PARTITION BY - subq_7.metric_time__week - , subq_7.metric_time__quarter - ORDER BY subq_7.metric_time__day + subq_6.metric_time__week + , subq_6.metric_time__quarter + ORDER BY subq_6.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS revenue_all_time FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__week - , subq_6.metric_time__quarter - , subq_6.txn_revenue AS revenue_all_time + subq_5.metric_time__day + , subq_5.metric_time__week + , subq_5.metric_time__quarter + , subq_5.txn_revenue AS revenue_all_time FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__week - , subq_5.metric_time__quarter - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.metric_time__day + , subq_4.metric_time__week + , subq_4.metric_time__quarter + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__quarter', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__week - , subq_4.metric_time__quarter - , subq_4.txn_revenue + subq_2.metric_time__day AS metric_time__day + , subq_2.metric_time__week AS metric_time__week + , subq_2.metric_time__quarter AS metric_time__quarter + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__week AS metric_time__week - , subq_2.metric_time__quarter AS metric_time__quarter - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS metric_time__day + , DATE_TRUNC('week', subq_3.ds) AS metric_time__week + , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter + FROM ***************************.mf_time_spine subq_3 + GROUP BY + subq_3.ds + , DATE_TRUNC('week', subq_3.ds) + , DATE_TRUNC('quarter', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('week', subq_3.ds) AS metric_time__week - , DATE_TRUNC('quarter', subq_3.ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - , DATE_TRUNC('quarter', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - (subq_1.metric_time__day <= subq_2.metric_time__day) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + (subq_1.metric_time__day <= subq_2.metric_time__day) + ) subq_4 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__week - , subq_5.metric_time__quarter - ) subq_6 - ) subq_7 -) subq_8 + subq_4.metric_time__day + , subq_4.metric_time__week + , subq_4.metric_time__quarter + ) subq_5 + ) subq_6 +) subq_7 GROUP BY - subq_8.metric_time__week - , subq_8.metric_time__quarter - , subq_8.revenue_all_time + subq_7.metric_time__week + , subq_7.metric_time__quarter + , subq_7.revenue_all_time diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql index ea37c15884..85c9a302de 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_all_time_metric_with_non_default_grains__plan0_optimized.sql @@ -21,9 +21,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__quarter AS metric_time__quarter + subq_10.metric_time__day AS metric_time__day + , subq_10.metric_time__week AS metric_time__week + , subq_10.metric_time__quarter AS metric_time__quarter , SUM(revenue_src_28000.revenue) AS revenue_all_time FROM ( -- Time Spine @@ -31,24 +31,24 @@ FROM ( ds AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week , DATE_TRUNC('quarter', ds) AS metric_time__quarter - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine subq_11 GROUP BY ds , DATE_TRUNC('week', ds) , DATE_TRUNC('quarter', ds) - ) subq_11 + ) subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.metric_time__day ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__quarter - ) subq_16 -) subq_17 + subq_10.metric_time__day + , subq_10.metric_time__week + , subq_10.metric_time__quarter + ) subq_14 +) subq_15 GROUP BY metric_time__week , metric_time__quarter diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric__plan0.sql index 1a2054d9f9..cd18af5e1d 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric__plan0.sql @@ -1,88 +1,49 @@ -- Compute Metrics via Expressions SELECT - subq_3.ds__day - , subq_3.txn_revenue AS trailing_2_months_revenue + subq_2.ds__day + , subq_2.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - subq_2.ds__day - , SUM(subq_2.txn_revenue) AS txn_revenue + subq_1.ds__day + , SUM(subq_1.txn_revenue) AS txn_revenue FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['txn_revenue', 'ds__day'] SELECT - subq_1.ds__day - , subq_1.txn_revenue + subq_0.ds__day + , subq_0.txn_revenue FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.ds__day -) subq_3 + subq_1.ds__day +) subq_2 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_grain_to_date__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_grain_to_date__plan0.sql index 1eb2b47b63..43798fdb52 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_grain_to_date__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_grain_to_date__plan0.sql @@ -1,88 +1,49 @@ -- Compute Metrics via Expressions SELECT - subq_3.ds__month - , subq_3.txn_revenue AS revenue_mtd + subq_2.ds__month + , subq_2.txn_revenue AS revenue_mtd FROM ( -- Aggregate Measures SELECT - subq_2.ds__month - , SUM(subq_2.txn_revenue) AS txn_revenue + subq_1.ds__month + , SUM(subq_1.txn_revenue) AS txn_revenue FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['txn_revenue', 'ds__month'] SELECT - subq_1.ds__month - , subq_1.txn_revenue + subq_0.ds__month + , subq_0.txn_revenue FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.ds__month -) subq_3 + subq_1.ds__month +) subq_2 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_month__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_month__plan0.sql index 238774265f..638a5d1461 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_month__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_month__plan0.sql @@ -1,136 +1,112 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__month - , subq_8.bookings_monthly AS trailing_3_months_bookings + subq_7.metric_time__month + , subq_7.bookings_monthly AS trailing_3_months_bookings FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__month - , SUM(subq_7.bookings_monthly) AS bookings_monthly + subq_6.metric_time__month + , SUM(subq_6.bookings_monthly) AS bookings_monthly FROM ( -- Constrain Time Range to [2020-03-05T00:00:00, 2021-01-04T00:00:00] SELECT - subq_6.metric_time__month - , subq_6.bookings_monthly + subq_5.metric_time__month + , subq_5.bookings_monthly FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['bookings_monthly', 'metric_time__month'] SELECT - subq_5.metric_time__month - , subq_5.bookings_monthly + subq_3.metric_time__month AS metric_time__month + , subq_2.bookings_monthly AS bookings_monthly FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_3.metric_time__month AS metric_time__month - , subq_2.monthly_ds__month AS monthly_ds__month - , subq_2.monthly_ds__quarter AS monthly_ds__quarter - , subq_2.monthly_ds__year AS monthly_ds__year - , subq_2.monthly_ds__extract_year AS monthly_ds__extract_year - , subq_2.monthly_ds__extract_quarter AS monthly_ds__extract_quarter - , subq_2.monthly_ds__extract_month AS monthly_ds__extract_month - , subq_2.booking__monthly_ds__month AS booking__monthly_ds__month - , subq_2.booking__monthly_ds__quarter AS booking__monthly_ds__quarter - , subq_2.booking__monthly_ds__year AS booking__monthly_ds__year - , subq_2.booking__monthly_ds__extract_year AS booking__monthly_ds__extract_year - , subq_2.booking__monthly_ds__extract_quarter AS booking__monthly_ds__extract_quarter - , subq_2.booking__monthly_ds__extract_month AS booking__monthly_ds__extract_month - , subq_2.metric_time__quarter AS metric_time__quarter - , subq_2.metric_time__year AS metric_time__year - , subq_2.metric_time__extract_year AS metric_time__extract_year - , subq_2.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_2.metric_time__extract_month AS metric_time__extract_month - , subq_2.listing AS listing - , subq_2.booking__listing AS booking__listing - , subq_2.bookings_monthly AS bookings_monthly + DATE_TRUNC('month', subq_4.ds) AS metric_time__month + FROM ***************************.mf_time_spine subq_4 + WHERE subq_4.ds BETWEEN '2020-03-05' AND '2021-01-04' + GROUP BY + DATE_TRUNC('month', subq_4.ds) + ) subq_3 + INNER JOIN ( + -- Constrain Time Range to [2019-12-05T00:00:00, 2021-01-04T00:00:00] + SELECT + subq_1.monthly_ds__month + , subq_1.monthly_ds__quarter + , subq_1.monthly_ds__year + , subq_1.monthly_ds__extract_year + , subq_1.monthly_ds__extract_quarter + , subq_1.monthly_ds__extract_month + , subq_1.booking__monthly_ds__month + , subq_1.booking__monthly_ds__quarter + , subq_1.booking__monthly_ds__year + , subq_1.booking__monthly_ds__extract_year + , subq_1.booking__monthly_ds__extract_quarter + , subq_1.booking__monthly_ds__extract_month + , subq_1.metric_time__month + , subq_1.metric_time__quarter + , subq_1.metric_time__year + , subq_1.metric_time__extract_year + , subq_1.metric_time__extract_quarter + , subq_1.metric_time__extract_month + , subq_1.listing + , subq_1.booking__listing + , subq_1.bookings_monthly FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', subq_4.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_4 - WHERE subq_4.ds BETWEEN '2020-03-05' AND '2021-01-04' - GROUP BY - DATE_TRUNC('month', subq_4.ds) - ) subq_3 - INNER JOIN ( - -- Constrain Time Range to [2019-12-05T00:00:00, 2021-01-04T00:00:00] + -- Metric Time Dimension 'monthly_ds' SELECT - subq_1.monthly_ds__month - , subq_1.monthly_ds__quarter - , subq_1.monthly_ds__year - , subq_1.monthly_ds__extract_year - , subq_1.monthly_ds__extract_quarter - , subq_1.monthly_ds__extract_month - , subq_1.booking__monthly_ds__month - , subq_1.booking__monthly_ds__quarter - , subq_1.booking__monthly_ds__year - , subq_1.booking__monthly_ds__extract_year - , subq_1.booking__monthly_ds__extract_quarter - , subq_1.booking__monthly_ds__extract_month - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.listing - , subq_1.booking__listing - , subq_1.bookings_monthly + subq_0.monthly_ds__month + , subq_0.monthly_ds__quarter + , subq_0.monthly_ds__year + , subq_0.monthly_ds__extract_year + , subq_0.monthly_ds__extract_quarter + , subq_0.monthly_ds__extract_month + , subq_0.booking__monthly_ds__month + , subq_0.booking__monthly_ds__quarter + , subq_0.booking__monthly_ds__year + , subq_0.booking__monthly_ds__extract_year + , subq_0.booking__monthly_ds__extract_quarter + , subq_0.booking__monthly_ds__extract_month + , subq_0.monthly_ds__month AS metric_time__month + , subq_0.monthly_ds__quarter AS metric_time__quarter + , subq_0.monthly_ds__year AS metric_time__year + , subq_0.monthly_ds__extract_year AS metric_time__extract_year + , subq_0.monthly_ds__extract_quarter AS metric_time__extract_quarter + , subq_0.monthly_ds__extract_month AS metric_time__extract_month + , subq_0.listing + , subq_0.booking__listing + , subq_0.bookings_monthly FROM ( - -- Metric Time Dimension 'monthly_ds' + -- Read Elements From Semantic Model 'bookings_monthly_source' SELECT - subq_0.monthly_ds__month - , subq_0.monthly_ds__quarter - , subq_0.monthly_ds__year - , subq_0.monthly_ds__extract_year - , subq_0.monthly_ds__extract_quarter - , subq_0.monthly_ds__extract_month - , subq_0.booking__monthly_ds__month - , subq_0.booking__monthly_ds__quarter - , subq_0.booking__monthly_ds__year - , subq_0.booking__monthly_ds__extract_year - , subq_0.booking__monthly_ds__extract_quarter - , subq_0.booking__monthly_ds__extract_month - , subq_0.monthly_ds__month AS metric_time__month - , subq_0.monthly_ds__quarter AS metric_time__quarter - , subq_0.monthly_ds__year AS metric_time__year - , subq_0.monthly_ds__extract_year AS metric_time__extract_year - , subq_0.monthly_ds__extract_quarter AS metric_time__extract_quarter - , subq_0.monthly_ds__extract_month AS metric_time__extract_month - , subq_0.listing - , subq_0.booking__listing - , subq_0.bookings_monthly - FROM ( - -- Read Elements From Semantic Model 'bookings_monthly_source' - SELECT - bookings_monthly_source_src_16000.bookings_monthly - , DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) AS monthly_ds__month - , DATE_TRUNC('quarter', bookings_monthly_source_src_16000.ds) AS monthly_ds__quarter - , DATE_TRUNC('year', bookings_monthly_source_src_16000.ds) AS monthly_ds__year - , EXTRACT(year FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_year - , EXTRACT(quarter FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_quarter - , EXTRACT(month FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_month - , DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__month - , DATE_TRUNC('quarter', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__quarter - , DATE_TRUNC('year', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__year - , EXTRACT(year FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_year - , EXTRACT(quarter FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_quarter - , EXTRACT(month FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_month - , bookings_monthly_source_src_16000.listing_id AS listing - , bookings_monthly_source_src_16000.listing_id AS booking__listing - FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_16000 - ) subq_0 - ) subq_1 - WHERE subq_1.metric_time__month BETWEEN '2019-12-05' AND '2021-01-04' - ) subq_2 - ON - ( - subq_2.metric_time__month <= subq_3.metric_time__month - ) AND ( - subq_2.metric_time__month > subq_3.metric_time__month - INTERVAL 3 month - ) - ) subq_5 - ) subq_6 - WHERE subq_6.metric_time__month BETWEEN '2020-03-05' AND '2021-01-04' - ) subq_7 + bookings_monthly_source_src_16000.bookings_monthly + , DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) AS monthly_ds__month + , DATE_TRUNC('quarter', bookings_monthly_source_src_16000.ds) AS monthly_ds__quarter + , DATE_TRUNC('year', bookings_monthly_source_src_16000.ds) AS monthly_ds__year + , EXTRACT(year FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_year + , EXTRACT(quarter FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_quarter + , EXTRACT(month FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_month + , DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__month + , DATE_TRUNC('quarter', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__quarter + , DATE_TRUNC('year', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__year + , EXTRACT(year FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_year + , EXTRACT(quarter FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_quarter + , EXTRACT(month FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_month + , bookings_monthly_source_src_16000.listing_id AS listing + , bookings_monthly_source_src_16000.listing_id AS booking__listing + FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_16000 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__month BETWEEN '2019-12-05' AND '2021-01-04' + ) subq_2 + ON + ( + subq_2.metric_time__month <= subq_3.metric_time__month + ) AND ( + subq_2.metric_time__month > subq_3.metric_time__month - INTERVAL 3 month + ) + ) subq_5 + WHERE subq_5.metric_time__month BETWEEN '2020-03-05' AND '2021-01-04' + ) subq_6 GROUP BY - subq_7.metric_time__month -) subq_8 + subq_6.metric_time__month +) subq_7 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_month__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_month__plan0_optimized.sql index df00087c33..0a1e7a3fe2 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_month__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_month__plan0_optimized.sql @@ -4,17 +4,17 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__month AS metric_time__month - , SUM(subq_11.bookings_monthly) AS trailing_3_months_bookings + subq_11.metric_time__month AS metric_time__month + , SUM(subq_10.bookings_monthly) AS trailing_3_months_bookings FROM ( -- Time Spine SELECT DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_12 WHERE ds BETWEEN '2020-03-05' AND '2021-01-04' GROUP BY DATE_TRUNC('month', ds) -) subq_12 +) subq_11 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_monthly_source' -- Metric Time Dimension 'monthly_ds' @@ -24,13 +24,13 @@ INNER JOIN ( , bookings_monthly FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_16000 WHERE DATE_TRUNC('month', ds) BETWEEN '2019-12-05' AND '2021-01-04' -) subq_11 +) subq_10 ON ( - subq_11.metric_time__month <= subq_12.metric_time__month + subq_10.metric_time__month <= subq_11.metric_time__month ) AND ( - subq_11.metric_time__month > subq_12.metric_time__month - INTERVAL 3 month + subq_10.metric_time__month > subq_11.metric_time__month - INTERVAL 3 month ) -WHERE subq_12.metric_time__month BETWEEN '2020-03-05' AND '2021-01-04' +WHERE subq_11.metric_time__month BETWEEN '2020-03-05' AND '2021-01-04' GROUP BY - subq_12.metric_time__month + subq_11.metric_time__month diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_ds__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_ds__plan0.sql index a25afde605..deed4ba82a 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_ds__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_ds__plan0.sql @@ -1,83 +1,44 @@ -- Compute Metrics via Expressions SELECT - subq_3.txn_revenue AS trailing_2_months_revenue + subq_2.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - SUM(subq_2.txn_revenue) AS txn_revenue + SUM(subq_1.txn_revenue) AS txn_revenue FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['txn_revenue',] SELECT - subq_1.txn_revenue + subq_0.txn_revenue FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 -) subq_3 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 +) subq_2 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window__plan0.sql index 740c26e8b4..4140894d47 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window__plan0.sql @@ -1,88 +1,49 @@ -- Compute Metrics via Expressions SELECT - subq_3.ds__month - , subq_3.txn_revenue AS revenue_all_time + subq_2.ds__month + , subq_2.txn_revenue AS revenue_all_time FROM ( -- Aggregate Measures SELECT - subq_2.ds__month - , SUM(subq_2.txn_revenue) AS txn_revenue + subq_1.ds__month + , SUM(subq_1.txn_revenue) AS txn_revenue FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['txn_revenue', 'ds__month'] SELECT - subq_1.ds__month - , subq_1.txn_revenue + subq_0.ds__month + , subq_0.txn_revenue FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.ds__month -) subq_3 + subq_1.ds__month +) subq_2 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0.sql index 8af29da836..89ebe003cb 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0.sql @@ -1,185 +1,146 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.txn_revenue AS revenue_all_time + subq_7.metric_time__day + , subq_7.txn_revenue AS revenue_all_time FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.txn_revenue) AS txn_revenue + subq_6.metric_time__day + , SUM(subq_6.txn_revenue) AS txn_revenue FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] SELECT - subq_6.metric_time__day - , subq_6.txn_revenue + subq_5.metric_time__day + , subq_5.txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__day'] SELECT - subq_5.metric_time__day - , subq_5.txn_revenue + subq_3.metric_time__day AS metric_time__day + , subq_2.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_3.metric_time__day AS metric_time__day - , subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_2.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_2.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_2.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_2.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_2.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_2.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_2.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_2.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_2.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_2.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_2.metric_time__week AS metric_time__week - , subq_2.metric_time__month AS metric_time__month - , subq_2.metric_time__quarter AS metric_time__quarter - , subq_2.metric_time__year AS metric_time__year - , subq_2.metric_time__extract_year AS metric_time__extract_year - , subq_2.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_2.metric_time__extract_month AS metric_time__extract_month - , subq_2.metric_time__extract_day AS metric_time__extract_day - , subq_2.metric_time__extract_dow AS metric_time__extract_dow - , subq_2.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.user AS user - , subq_2.revenue_instance__user AS revenue_instance__user - , subq_2.txn_revenue AS txn_revenue + subq_4.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_4 + WHERE subq_4.ds BETWEEN '2020-01-01' AND '2020-01-01' + ) subq_3 + INNER JOIN ( + -- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00] + SELECT + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.revenue_instance__ds__day + , subq_1.revenue_instance__ds__week + , subq_1.revenue_instance__ds__month + , subq_1.revenue_instance__ds__quarter + , subq_1.revenue_instance__ds__year + , subq_1.revenue_instance__ds__extract_year + , subq_1.revenue_instance__ds__extract_quarter + , subq_1.revenue_instance__ds__extract_month + , subq_1.revenue_instance__ds__extract_day + , subq_1.revenue_instance__ds__extract_dow + , subq_1.revenue_instance__ds__extract_doy + , subq_1.metric_time__day + , subq_1.metric_time__week + , subq_1.metric_time__month + , subq_1.metric_time__quarter + , subq_1.metric_time__year + , subq_1.metric_time__extract_year + , subq_1.metric_time__extract_quarter + , subq_1.metric_time__extract_month + , subq_1.metric_time__extract_day + , subq_1.metric_time__extract_dow + , subq_1.metric_time__extract_doy + , subq_1.user + , subq_1.revenue_instance__user + , subq_1.txn_revenue FROM ( - -- Time Spine - SELECT - subq_4.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_4 - WHERE subq_4.ds BETWEEN '2020-01-01' AND '2020-01-01' - ) subq_3 - INNER JOIN ( - -- Constrain Time Range to [2000-01-01T00:00:00, 2020-01-01T00:00:00] + -- Metric Time Dimension 'ds' SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.revenue_instance__ds__day - , subq_1.revenue_instance__ds__week - , subq_1.revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.user - , subq_1.revenue_instance__user - , subq_1.txn_revenue + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01' - ) subq_2 - ON - (subq_2.metric_time__day <= subq_3.metric_time__day) - ) subq_5 - ) subq_6 - WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' - ) subq_7 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2000-01-01' AND '2020-01-01' + ) subq_2 + ON + (subq_2.metric_time__day <= subq_3.metric_time__day) + ) subq_5 + WHERE subq_5.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' + ) subq_6 GROUP BY - subq_7.metric_time__day -) subq_8 + subq_6.metric_time__day +) subq_7 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql index 0c658869b2..5fa2146ea7 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_no_window_with_time_constraint__plan0_optimized.sql @@ -4,15 +4,15 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , SUM(subq_11.txn_revenue) AS revenue_all_time + subq_11.metric_time__day AS metric_time__day + , SUM(subq_10.txn_revenue) AS revenue_all_time FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_12 WHERE ds BETWEEN '2020-01-01' AND '2020-01-01' -) subq_12 +) subq_11 INNER JOIN ( -- Read Elements From Semantic Model 'revenue' -- Metric Time Dimension 'ds' @@ -22,9 +22,9 @@ INNER JOIN ( , revenue AS txn_revenue FROM ***************************.fct_revenue revenue_src_28000 WHERE DATE_TRUNC('day', created_at) BETWEEN '2000-01-01' AND '2020-01-01' -) subq_11 +) subq_10 ON - (subq_11.metric_time__day <= subq_12.metric_time__day) -WHERE subq_12.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' + (subq_10.metric_time__day <= subq_11.metric_time__day) +WHERE subq_11.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' GROUP BY - subq_12.metric_time__day + subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql index 78a6550fbd..e062be0b9a 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0.sql @@ -1,148 +1,109 @@ -- Compute Metrics via Expressions SELECT - subq_6.revenue_instance__ds__month - , subq_6.metric_time__day - , subq_6.txn_revenue AS trailing_2_months_revenue + subq_5.revenue_instance__ds__month + , subq_5.metric_time__day + , subq_5.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - subq_5.revenue_instance__ds__month - , subq_5.metric_time__day - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.revenue_instance__ds__month + , subq_4.metric_time__day + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__day', 'revenue_instance__ds__month'] SELECT - subq_4.revenue_instance__ds__month - , subq_4.metric_time__day - , subq_4.txn_revenue + subq_2.revenue_instance__ds__month AS revenue_instance__ds__month + , subq_2.metric_time__day AS metric_time__day + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_2.metric_time__day AS metric_time__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month + , subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('month', subq_3.ds) + , subq_3.ds + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month - , subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month - ) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month + ) + ) subq_4 GROUP BY - subq_5.revenue_instance__ds__month - , subq_5.metric_time__day -) subq_6 + subq_4.revenue_instance__ds__month + , subq_4.metric_time__day +) subq_5 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql index eaaba26ba2..f0713ca4aa 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_and_metric_time__plan0_optimized.sql @@ -3,27 +3,27 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_9.metric_time__day AS metric_time__day + subq_8.revenue_instance__ds__month AS revenue_instance__ds__month + , subq_8.metric_time__day AS metric_time__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine SELECT DATE_TRUNC('month', ds) AS revenue_instance__ds__month , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 + FROM ***************************.mf_time_spine subq_9 GROUP BY DATE_TRUNC('month', ds) , ds -) subq_9 +) subq_8 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_8.metric_time__day ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.metric_time__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_8.metric_time__day - INTERVAL 2 month ) GROUP BY - subq_9.revenue_instance__ds__month - , subq_9.metric_time__day + subq_8.revenue_instance__ds__month + , subq_8.metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0.sql index 126f491236..9f4694c022 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0.sql @@ -1,140 +1,101 @@ -- Compute Metrics via Expressions SELECT - subq_6.revenue_instance__ds__day - , subq_6.txn_revenue AS trailing_2_months_revenue + subq_5.revenue_instance__ds__day + , subq_5.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - subq_5.revenue_instance__ds__day - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.revenue_instance__ds__day + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'revenue_instance__ds__day'] SELECT - subq_4.revenue_instance__ds__day - , subq_4.txn_revenue + subq_2.revenue_instance__ds__day AS revenue_instance__ds__day + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__day AS metric_time__day - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS revenue_instance__ds__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS revenue_instance__ds__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.revenue_instance__ds__day <= subq_2.revenue_instance__ds__day - ) AND ( - subq_1.revenue_instance__ds__day > subq_2.revenue_instance__ds__day - INTERVAL 2 month - ) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.revenue_instance__ds__day <= subq_2.revenue_instance__ds__day + ) AND ( + subq_1.revenue_instance__ds__day > subq_2.revenue_instance__ds__day - INTERVAL 2 month + ) + ) subq_4 GROUP BY - subq_5.revenue_instance__ds__day -) subq_6 + subq_4.revenue_instance__ds__day +) subq_5 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0_optimized.sql index 4719e4a5ff..a6122afaa4 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_agg_time_dimension__plan0_optimized.sql @@ -3,16 +3,16 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.ds AS revenue_instance__ds__day + subq_9.ds AS revenue_instance__ds__day , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue -FROM ***************************.mf_time_spine subq_10 +FROM ***************************.mf_time_spine subq_9 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.ds + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.ds ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.ds - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.ds - INTERVAL 2 month ) GROUP BY - subq_10.ds + subq_9.ds diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql index 08079e14cc..54e8f8aa55 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0.sql @@ -1,148 +1,109 @@ -- Compute Metrics via Expressions SELECT - subq_6.revenue_instance__ds__day - , subq_6.revenue_instance__ds__month - , subq_6.txn_revenue AS trailing_2_months_revenue + subq_5.revenue_instance__ds__day + , subq_5.revenue_instance__ds__month + , subq_5.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - subq_5.revenue_instance__ds__day - , subq_5.revenue_instance__ds__month - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.revenue_instance__ds__day + , subq_4.revenue_instance__ds__month + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'revenue_instance__ds__day', 'revenue_instance__ds__month'] SELECT - subq_4.revenue_instance__ds__day - , subq_4.revenue_instance__ds__month - , subq_4.txn_revenue + subq_2.revenue_instance__ds__day AS revenue_instance__ds__day + , subq_2.revenue_instance__ds__month AS revenue_instance__ds__month + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_2.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__day AS metric_time__day - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS revenue_instance__ds__day + , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month + FROM ***************************.mf_time_spine subq_3 + GROUP BY + subq_3.ds + , DATE_TRUNC('month', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS revenue_instance__ds__day - , DATE_TRUNC('month', subq_3.ds) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.revenue_instance__ds__day <= subq_2.revenue_instance__ds__day - ) AND ( - subq_1.revenue_instance__ds__day > subq_2.revenue_instance__ds__day - INTERVAL 2 month - ) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.revenue_instance__ds__day <= subq_2.revenue_instance__ds__day + ) AND ( + subq_1.revenue_instance__ds__day > subq_2.revenue_instance__ds__day - INTERVAL 2 month + ) + ) subq_4 GROUP BY - subq_5.revenue_instance__ds__day - , subq_5.revenue_instance__ds__month -) subq_6 + subq_4.revenue_instance__ds__day + , subq_4.revenue_instance__ds__month +) subq_5 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql index df79dc0757..c172c05360 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_agg_time_dimensions__plan0_optimized.sql @@ -3,27 +3,27 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_9.revenue_instance__ds__month AS revenue_instance__ds__month + subq_8.revenue_instance__ds__day AS revenue_instance__ds__day + , subq_8.revenue_instance__ds__month AS revenue_instance__ds__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine SELECT ds AS revenue_instance__ds__day , DATE_TRUNC('month', ds) AS revenue_instance__ds__month - FROM ***************************.mf_time_spine subq_10 + FROM ***************************.mf_time_spine subq_9 GROUP BY ds , DATE_TRUNC('month', ds) -) subq_9 +) subq_8 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.revenue_instance__ds__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_8.revenue_instance__ds__day ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.revenue_instance__ds__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_8.revenue_instance__ds__day - INTERVAL 2 month ) GROUP BY - subq_9.revenue_instance__ds__day - , subq_9.revenue_instance__ds__month + subq_8.revenue_instance__ds__day + , subq_8.revenue_instance__ds__month diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql index ec77b12959..46b10543fd 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0.sql @@ -1,148 +1,109 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__month - , subq_6.txn_revenue AS trailing_2_months_revenue + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.metric_time__day + , subq_4.metric_time__month + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__day', 'metric_time__month'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.txn_revenue + subq_2.metric_time__day AS metric_time__day + , subq_2.metric_time__month AS metric_time__month + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS metric_time__day + , DATE_TRUNC('month', subq_3.ds) AS metric_time__month + FROM ***************************.mf_time_spine subq_3 + GROUP BY + subq_3.ds + , DATE_TRUNC('month', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month - ) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month + ) + ) subq_4 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month -) subq_6 + subq_4.metric_time__day + , subq_4.metric_time__month +) subq_5 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql index 5a4fb59200..dce5c1f860 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_multiple_metric_time_dimensions__plan0_optimized.sql @@ -3,27 +3,27 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day AS metric_time__day - , subq_9.metric_time__month AS metric_time__month + subq_8.metric_time__day AS metric_time__day + , subq_8.metric_time__month AS metric_time__month , SUM(revenue_src_28000.revenue) AS trailing_2_months_revenue FROM ( -- Time Spine SELECT ds AS metric_time__day , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_10 + FROM ***************************.mf_time_spine subq_9 GROUP BY ds , DATE_TRUNC('month', ds) -) subq_9 +) subq_8 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_9.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_8.metric_time__day ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_9.metric_time__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_8.metric_time__day - INTERVAL 2 month ) GROUP BY - subq_9.metric_time__day - , subq_9.metric_time__month + subq_8.metric_time__day + , subq_8.metric_time__month diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql index 1a771a2886..6605f8615b 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0.sql @@ -1,334 +1,233 @@ -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.bookers AS every_two_days_bookers + subq_6.metric_time__day + , subq_6.bookers AS every_two_days_bookers FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__day - , COUNT(DISTINCT subq_6.bookers) AS bookers + subq_5.metric_time__day + , COUNT(DISTINCT subq_5.bookers) AS bookers FROM ( -- Constrain Output with WHERE SELECT - subq_5.metric_time__day - , subq_5.bookers + subq_4.metric_time__day + , subq_4.bookers FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookers + subq_2.metric_time__day AS metric_time__day + , subq_1.bookers AS bookers FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day - ) - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day + ) + ) subq_4 WHERE metric_time__day = '2020-01-03' or metric_time__day = '2020-01-07' - ) subq_6 + ) subq_5 GROUP BY - subq_6.metric_time__day -) subq_7 + subq_5.metric_time__day +) subq_6 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql index e62e61f0c3..f94038d28e 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_adjustable_time_filter__plan0_optimized.sql @@ -8,18 +8,18 @@ FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_11.ds AS metric_time__day + subq_10.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_11 + FROM ***************************.mf_time_spine subq_10 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_11.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_10.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_11.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_10.ds - INTERVAL 2 day ) -) subq_13 +) subq_11 WHERE metric_time__day = '2020-01-03' or metric_time__day = '2020-01-07' GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql index a83909ad88..b42f587321 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0.sql @@ -1,163 +1,124 @@ -- Re-aggregate Metric via Group By SELECT - subq_8.metric_time__week - , subq_8.revenue_all_time + subq_7.metric_time__week + , subq_7.revenue_all_time FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_7.metric_time__week - , LAST_VALUE(subq_7.revenue_all_time) OVER ( - PARTITION BY subq_7.metric_time__week - ORDER BY subq_7.metric_time__day + subq_6.metric_time__week + , LAST_VALUE(subq_6.revenue_all_time) OVER ( + PARTITION BY subq_6.metric_time__week + ORDER BY subq_6.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS revenue_all_time FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__week - , subq_6.txn_revenue AS revenue_all_time + subq_5.metric_time__day + , subq_5.metric_time__week + , subq_5.txn_revenue AS revenue_all_time FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__week - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.metric_time__day + , subq_4.metric_time__week + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__week - , subq_4.txn_revenue + subq_2.metric_time__day AS metric_time__day + , subq_2.metric_time__week AS metric_time__week + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__week AS metric_time__week - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS metric_time__day + , DATE_TRUNC('week', subq_3.ds) AS metric_time__week + FROM ***************************.mf_time_spine subq_3 + GROUP BY + subq_3.ds + , DATE_TRUNC('week', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('week', subq_3.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - (subq_1.metric_time__day <= subq_2.metric_time__day) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + (subq_1.metric_time__day <= subq_2.metric_time__day) + ) subq_4 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__week - ) subq_6 - ) subq_7 -) subq_8 + subq_4.metric_time__day + , subq_4.metric_time__week + ) subq_5 + ) subq_6 +) subq_7 GROUP BY - subq_8.metric_time__week - , subq_8.revenue_all_time + subq_7.metric_time__week + , subq_7.revenue_all_time diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql index 2b6f12b36c..4582f74b80 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_non_default_grain__plan0_optimized.sql @@ -17,30 +17,30 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week + subq_10.metric_time__day AS metric_time__day + , subq_10.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS revenue_all_time FROM ( -- Time Spine SELECT ds AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine subq_11 GROUP BY ds , DATE_TRUNC('week', ds) - ) subq_11 + ) subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.metric_time__day ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__week - ) subq_16 -) subq_17 + subq_10.metric_time__day + , subq_10.metric_time__week + ) subq_14 +) subq_15 GROUP BY metric_time__week , revenue_all_time diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0.sql index f381377090..92b3d6c892 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0.sql @@ -1,189 +1,150 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.txn_revenue AS trailing_2_months_revenue + subq_7.metric_time__day + , subq_7.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.txn_revenue) AS txn_revenue + subq_6.metric_time__day + , SUM(subq_6.txn_revenue) AS txn_revenue FROM ( -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] SELECT - subq_6.metric_time__day - , subq_6.txn_revenue + subq_5.metric_time__day + , subq_5.txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__day'] SELECT - subq_5.metric_time__day - , subq_5.txn_revenue + subq_3.metric_time__day AS metric_time__day + , subq_2.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_3.metric_time__day AS metric_time__day - , subq_2.ds__day AS ds__day - , subq_2.ds__week AS ds__week - , subq_2.ds__month AS ds__month - , subq_2.ds__quarter AS ds__quarter - , subq_2.ds__year AS ds__year - , subq_2.ds__extract_year AS ds__extract_year - , subq_2.ds__extract_quarter AS ds__extract_quarter - , subq_2.ds__extract_month AS ds__extract_month - , subq_2.ds__extract_day AS ds__extract_day - , subq_2.ds__extract_dow AS ds__extract_dow - , subq_2.ds__extract_doy AS ds__extract_doy - , subq_2.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_2.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_2.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_2.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_2.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_2.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_2.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_2.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_2.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_2.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_2.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_2.metric_time__week AS metric_time__week - , subq_2.metric_time__month AS metric_time__month - , subq_2.metric_time__quarter AS metric_time__quarter - , subq_2.metric_time__year AS metric_time__year - , subq_2.metric_time__extract_year AS metric_time__extract_year - , subq_2.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_2.metric_time__extract_month AS metric_time__extract_month - , subq_2.metric_time__extract_day AS metric_time__extract_day - , subq_2.metric_time__extract_dow AS metric_time__extract_dow - , subq_2.metric_time__extract_doy AS metric_time__extract_doy - , subq_2.user AS user - , subq_2.revenue_instance__user AS revenue_instance__user - , subq_2.txn_revenue AS txn_revenue + subq_4.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_4 + WHERE subq_4.ds BETWEEN '2020-01-01' AND '2020-01-01' + ) subq_3 + INNER JOIN ( + -- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00] + SELECT + subq_1.ds__day + , subq_1.ds__week + , subq_1.ds__month + , subq_1.ds__quarter + , subq_1.ds__year + , subq_1.ds__extract_year + , subq_1.ds__extract_quarter + , subq_1.ds__extract_month + , subq_1.ds__extract_day + , subq_1.ds__extract_dow + , subq_1.ds__extract_doy + , subq_1.revenue_instance__ds__day + , subq_1.revenue_instance__ds__week + , subq_1.revenue_instance__ds__month + , subq_1.revenue_instance__ds__quarter + , subq_1.revenue_instance__ds__year + , subq_1.revenue_instance__ds__extract_year + , subq_1.revenue_instance__ds__extract_quarter + , subq_1.revenue_instance__ds__extract_month + , subq_1.revenue_instance__ds__extract_day + , subq_1.revenue_instance__ds__extract_dow + , subq_1.revenue_instance__ds__extract_doy + , subq_1.metric_time__day + , subq_1.metric_time__week + , subq_1.metric_time__month + , subq_1.metric_time__quarter + , subq_1.metric_time__year + , subq_1.metric_time__extract_year + , subq_1.metric_time__extract_quarter + , subq_1.metric_time__extract_month + , subq_1.metric_time__extract_day + , subq_1.metric_time__extract_dow + , subq_1.metric_time__extract_doy + , subq_1.user + , subq_1.revenue_instance__user + , subq_1.txn_revenue FROM ( - -- Time Spine - SELECT - subq_4.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_4 - WHERE subq_4.ds BETWEEN '2020-01-01' AND '2020-01-01' - ) subq_3 - INNER JOIN ( - -- Constrain Time Range to [2019-11-01T00:00:00, 2020-01-01T00:00:00] + -- Metric Time Dimension 'ds' SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.revenue_instance__ds__day - , subq_1.revenue_instance__ds__week - , subq_1.revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.user - , subq_1.revenue_instance__user - , subq_1.txn_revenue + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2019-11-01' AND '2020-01-01' - ) subq_2 - ON - ( - subq_2.metric_time__day <= subq_3.metric_time__day - ) AND ( - subq_2.metric_time__day > subq_3.metric_time__day - INTERVAL 2 month - ) - ) subq_5 - ) subq_6 - WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' - ) subq_7 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2019-11-01' AND '2020-01-01' + ) subq_2 + ON + ( + subq_2.metric_time__day <= subq_3.metric_time__day + ) AND ( + subq_2.metric_time__day > subq_3.metric_time__day - INTERVAL 2 month + ) + ) subq_5 + WHERE subq_5.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' + ) subq_6 GROUP BY - subq_7.metric_time__day -) subq_8 + subq_6.metric_time__day +) subq_7 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0_optimized.sql index f6f5b25650..28b93ed647 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_time_constraint__plan0_optimized.sql @@ -4,15 +4,15 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day AS metric_time__day - , SUM(subq_11.txn_revenue) AS trailing_2_months_revenue + subq_11.metric_time__day AS metric_time__day + , SUM(subq_10.txn_revenue) AS trailing_2_months_revenue FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_12 WHERE ds BETWEEN '2020-01-01' AND '2020-01-01' -) subq_12 +) subq_11 INNER JOIN ( -- Read Elements From Semantic Model 'revenue' -- Metric Time Dimension 'ds' @@ -22,13 +22,13 @@ INNER JOIN ( , revenue AS txn_revenue FROM ***************************.fct_revenue revenue_src_28000 WHERE DATE_TRUNC('day', created_at) BETWEEN '2019-11-01' AND '2020-01-01' -) subq_11 +) subq_10 ON ( - subq_11.metric_time__day <= subq_12.metric_time__day + subq_10.metric_time__day <= subq_11.metric_time__day ) AND ( - subq_11.metric_time__day > subq_12.metric_time__day - INTERVAL 2 month + subq_10.metric_time__day > subq_11.metric_time__day - INTERVAL 2 month ) -WHERE subq_12.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' +WHERE subq_11.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' GROUP BY - subq_12.metric_time__day + subq_11.metric_time__day diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql index 95969c9da1..b373197fab 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0.sql @@ -1,169 +1,130 @@ -- Compute Metrics via Expressions SELECT - subq_9.metric_time__week + subq_8.metric_time__week , t2mr - 10 AS trailing_2_months_revenue_sub_10 FROM ( -- Re-aggregate Metric via Group By SELECT - subq_8.metric_time__week - , subq_8.t2mr + subq_7.metric_time__week + , subq_7.t2mr FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_7.metric_time__week - , AVG(subq_7.t2mr) OVER (PARTITION BY subq_7.metric_time__week) AS t2mr + subq_6.metric_time__week + , AVG(subq_6.t2mr) OVER (PARTITION BY subq_6.metric_time__week) AS t2mr FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__week - , subq_6.txn_revenue AS t2mr + subq_5.metric_time__day + , subq_5.metric_time__week + , subq_5.txn_revenue AS t2mr FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__week - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.metric_time__day + , subq_4.metric_time__week + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__week - , subq_4.txn_revenue + subq_2.metric_time__day AS metric_time__day + , subq_2.metric_time__week AS metric_time__week + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__week AS metric_time__week - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS metric_time__day + , DATE_TRUNC('week', subq_3.ds) AS metric_time__week + FROM ***************************.mf_time_spine subq_3 + GROUP BY + subq_3.ds + , DATE_TRUNC('week', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('week', subq_3.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month - ) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month + ) + ) subq_4 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__week - ) subq_6 - ) subq_7 - ) subq_8 + subq_4.metric_time__day + , subq_4.metric_time__week + ) subq_5 + ) subq_6 + ) subq_7 GROUP BY - subq_8.metric_time__week - , subq_8.t2mr -) subq_9 + subq_7.metric_time__week + , subq_7.t2mr +) subq_8 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql index 363d16e9bd..1d2c75b464 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_cumulative_metric_with_non_default_grains__plan0_optimized.sql @@ -18,33 +18,33 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__week', 'metric_time__day'] -- Aggregate Measures SELECT - subq_12.metric_time__day AS metric_time__day - , subq_12.metric_time__week AS metric_time__week + subq_11.metric_time__day AS metric_time__day + , subq_11.metric_time__week AS metric_time__week , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT ds AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_12 GROUP BY ds , DATE_TRUNC('week', ds) - ) subq_12 + ) subq_11 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_12.metric_time__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_11.metric_time__day - INTERVAL 2 month ) GROUP BY - subq_12.metric_time__day - , subq_12.metric_time__week - ) subq_16 - ) subq_18 + subq_11.metric_time__day + , subq_11.metric_time__week + ) subq_14 + ) subq_16 GROUP BY metric_time__week , t2mr -) subq_19 +) subq_17 diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql index aab94914af..e65720561c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0.sql @@ -1,167 +1,128 @@ -- Re-aggregate Metric via Group By SELECT - subq_8.metric_time__month - , subq_8.revenue_mtd + subq_7.metric_time__month + , subq_7.revenue_mtd FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_7.metric_time__month - , FIRST_VALUE(subq_7.revenue_mtd) OVER ( - PARTITION BY subq_7.metric_time__month - ORDER BY subq_7.metric_time__day + subq_6.metric_time__month + , FIRST_VALUE(subq_6.revenue_mtd) OVER ( + PARTITION BY subq_6.metric_time__month + ORDER BY subq_6.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS revenue_mtd FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__month - , subq_6.txn_revenue AS revenue_mtd + subq_5.metric_time__day + , subq_5.metric_time__month + , subq_5.txn_revenue AS revenue_mtd FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.metric_time__day + , subq_4.metric_time__month + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__month', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.txn_revenue + subq_2.metric_time__day AS metric_time__day + , subq_2.metric_time__month AS metric_time__month + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__month AS metric_time__month - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS metric_time__day + , DATE_TRUNC('month', subq_3.ds) AS metric_time__month + FROM ***************************.mf_time_spine subq_3 + GROUP BY + subq_3.ds + , DATE_TRUNC('month', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('month', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day >= DATE_TRUNC('month', subq_2.metric_time__day) - ) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day >= DATE_TRUNC('month', subq_2.metric_time__day) + ) + ) subq_4 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - ) subq_6 - ) subq_7 -) subq_8 + subq_4.metric_time__day + , subq_4.metric_time__month + ) subq_5 + ) subq_6 +) subq_7 GROUP BY - subq_8.metric_time__month - , subq_8.revenue_mtd + subq_7.metric_time__month + , subq_7.revenue_mtd diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql index 0a70199c86..ad6f80e73c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grain__plan0_optimized.sql @@ -17,32 +17,32 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__month AS metric_time__month + subq_10.metric_time__day AS metric_time__day + , subq_10.metric_time__month AS metric_time__month , SUM(revenue_src_28000.revenue) AS revenue_mtd FROM ( -- Time Spine SELECT ds AS metric_time__day , DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine subq_11 GROUP BY ds , DATE_TRUNC('month', ds) - ) subq_11 + ) subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.metric_time__day ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_10.metric_time__day) ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__month - ) subq_16 -) subq_17 + subq_10.metric_time__day + , subq_10.metric_time__month + ) subq_14 +) subq_15 GROUP BY metric_time__month , revenue_mtd diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql index 92e8a38290..6e8dcff11c 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0.sql @@ -1,178 +1,139 @@ -- Re-aggregate Metric via Group By SELECT - subq_8.revenue_instance__ds__quarter - , subq_8.revenue_instance__ds__year - , subq_8.revenue_mtd + subq_7.revenue_instance__ds__quarter + , subq_7.revenue_instance__ds__year + , subq_7.revenue_mtd FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_7.revenue_instance__ds__quarter - , subq_7.revenue_instance__ds__year - , FIRST_VALUE(subq_7.revenue_mtd) OVER ( + subq_6.revenue_instance__ds__quarter + , subq_6.revenue_instance__ds__year + , FIRST_VALUE(subq_6.revenue_mtd) OVER ( PARTITION BY - subq_7.revenue_instance__ds__quarter - , subq_7.revenue_instance__ds__year - ORDER BY subq_7.metric_time__day + subq_6.revenue_instance__ds__quarter + , subq_6.revenue_instance__ds__year + ORDER BY subq_6.metric_time__day ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS revenue_mtd FROM ( -- Compute Metrics via Expressions SELECT - subq_6.revenue_instance__ds__quarter - , subq_6.revenue_instance__ds__year - , subq_6.metric_time__day - , subq_6.txn_revenue AS revenue_mtd + subq_5.revenue_instance__ds__quarter + , subq_5.revenue_instance__ds__year + , subq_5.metric_time__day + , subq_5.txn_revenue AS revenue_mtd FROM ( -- Aggregate Measures SELECT - subq_5.revenue_instance__ds__quarter - , subq_5.revenue_instance__ds__year - , subq_5.metric_time__day - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.revenue_instance__ds__quarter + , subq_4.revenue_instance__ds__year + , subq_4.metric_time__day + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'revenue_instance__ds__quarter', 'revenue_instance__ds__year', 'metric_time__day'] SELECT - subq_4.revenue_instance__ds__quarter - , subq_4.revenue_instance__ds__year - , subq_4.metric_time__day - , subq_4.txn_revenue + subq_2.revenue_instance__ds__quarter AS revenue_instance__ds__quarter + , subq_2.revenue_instance__ds__year AS revenue_instance__ds__year + , subq_2.metric_time__day AS metric_time__day + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_2.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_2.metric_time__day AS metric_time__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + DATE_TRUNC('quarter', subq_3.ds) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year + , subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('quarter', subq_3.ds) + , DATE_TRUNC('year', subq_3.ds) + , subq_3.ds + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - DATE_TRUNC('quarter', subq_3.ds) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', subq_3.ds) AS revenue_instance__ds__year - , subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('quarter', subq_3.ds) - , DATE_TRUNC('year', subq_3.ds) - , subq_3.ds - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day >= DATE_TRUNC('month', subq_2.metric_time__day) - ) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day >= DATE_TRUNC('month', subq_2.metric_time__day) + ) + ) subq_4 GROUP BY - subq_5.revenue_instance__ds__quarter - , subq_5.revenue_instance__ds__year - , subq_5.metric_time__day - ) subq_6 - ) subq_7 -) subq_8 + subq_4.revenue_instance__ds__quarter + , subq_4.revenue_instance__ds__year + , subq_4.metric_time__day + ) subq_5 + ) subq_6 +) subq_7 GROUP BY - subq_8.revenue_instance__ds__quarter - , subq_8.revenue_instance__ds__year - , subq_8.revenue_mtd + subq_7.revenue_instance__ds__quarter + , subq_7.revenue_instance__ds__year + , subq_7.revenue_mtd diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql index 8f10523e66..755def09bf 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_grain_to_date_metric_with_non_default_grains__plan0_optimized.sql @@ -21,9 +21,9 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_11.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_11.metric_time__day AS metric_time__day + subq_10.revenue_instance__ds__quarter AS revenue_instance__ds__quarter + , subq_10.revenue_instance__ds__year AS revenue_instance__ds__year + , subq_10.metric_time__day AS metric_time__day , SUM(revenue_src_28000.revenue) AS revenue_mtd FROM ( -- Time Spine @@ -31,26 +31,26 @@ FROM ( DATE_TRUNC('quarter', ds) AS revenue_instance__ds__quarter , DATE_TRUNC('year', ds) AS revenue_instance__ds__year , ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine subq_11 GROUP BY DATE_TRUNC('quarter', ds) , DATE_TRUNC('year', ds) , ds - ) subq_11 + ) subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.metric_time__day ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_11.metric_time__day) + DATE_TRUNC('day', revenue_src_28000.created_at) >= DATE_TRUNC('month', subq_10.metric_time__day) ) GROUP BY - subq_11.revenue_instance__ds__quarter - , subq_11.revenue_instance__ds__year - , subq_11.metric_time__day - ) subq_16 -) subq_17 + subq_10.revenue_instance__ds__quarter + , subq_10.revenue_instance__ds__year + , subq_10.metric_time__day + ) subq_14 +) subq_15 GROUP BY revenue_instance__ds__quarter , revenue_instance__ds__year diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql index cf6722d1ca..326f858fb9 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0.sql @@ -1,163 +1,124 @@ -- Re-aggregate Metric via Group By SELECT - subq_8.metric_time__year - , subq_8.trailing_2_months_revenue + subq_7.metric_time__year + , subq_7.trailing_2_months_revenue FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_7.metric_time__year - , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__year) AS trailing_2_months_revenue + subq_6.metric_time__year + , AVG(subq_6.trailing_2_months_revenue) OVER (PARTITION BY subq_6.metric_time__year) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.metric_time__year - , subq_6.txn_revenue AS trailing_2_months_revenue + subq_5.metric_time__day + , subq_5.metric_time__year + , subq_5.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , subq_5.metric_time__year - , SUM(subq_5.txn_revenue) AS txn_revenue + subq_4.metric_time__day + , subq_4.metric_time__year + , SUM(subq_4.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.metric_time__year - , subq_4.txn_revenue + subq_2.metric_time__day AS metric_time__day + , subq_2.metric_time__year AS metric_time__year + , subq_1.txn_revenue AS txn_revenue FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__year AS metric_time__year - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS metric_time__day + , DATE_TRUNC('year', subq_3.ds) AS metric_time__year + FROM ***************************.mf_time_spine subq_3 + GROUP BY + subq_3.ds + , DATE_TRUNC('year', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - , DATE_TRUNC('year', subq_3.ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_3 - GROUP BY - subq_3.ds - , DATE_TRUNC('year', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month - ) - ) subq_4 - ) subq_5 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month + ) + ) subq_4 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__year - ) subq_6 - ) subq_7 -) subq_8 + subq_4.metric_time__day + , subq_4.metric_time__year + ) subq_5 + ) subq_6 +) subq_7 GROUP BY - subq_8.metric_time__year - , subq_8.trailing_2_months_revenue + subq_7.metric_time__year + , subq_7.trailing_2_months_revenue diff --git a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql index 03e4ba7fc4..d2b9fbd751 100644 --- a/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_cumulative_metric_rendering.py/SqlQueryPlan/DuckDB/test_window_metric_with_non_default_grain__plan0_optimized.sql @@ -13,32 +13,32 @@ FROM ( -- Pass Only Elements: ['txn_revenue', 'metric_time__year', 'metric_time__day'] -- Aggregate Measures SELECT - subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__year AS metric_time__year + subq_10.metric_time__day AS metric_time__day + , subq_10.metric_time__year AS metric_time__year , SUM(revenue_src_28000.revenue) AS txn_revenue FROM ( -- Time Spine SELECT ds AS metric_time__day , DATE_TRUNC('year', ds) AS metric_time__year - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine subq_11 GROUP BY ds , DATE_TRUNC('year', ds) - ) subq_11 + ) subq_10 INNER JOIN ***************************.fct_revenue revenue_src_28000 ON ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_11.metric_time__day + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_10.metric_time__day ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_11.metric_time__day - INTERVAL 2 month + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_10.metric_time__day - INTERVAL 2 month ) GROUP BY - subq_11.metric_time__day - , subq_11.metric_time__year - ) subq_15 -) subq_17 + subq_10.metric_time__day + , subq_10.metric_time__year + ) subq_13 +) subq_15 GROUP BY metric_time__year , trailing_2_months_revenue 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 113268bbb1..f9766407e8 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 @@ -1,381 +1,280 @@ -- Re-aggregate Metric via Group By SELECT - subq_11.metric_time__week - , subq_11.booking__ds__month - , subq_11.every_two_days_bookers_fill_nulls_with_0 + subq_10.metric_time__week + , subq_10.booking__ds__month + , subq_10.every_two_days_bookers_fill_nulls_with_0 FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_10.metric_time__week - , subq_10.booking__ds__month - , FIRST_VALUE(subq_10.every_two_days_bookers_fill_nulls_with_0) OVER ( + subq_9.metric_time__week + , subq_9.booking__ds__month + , FIRST_VALUE(subq_9.every_two_days_bookers_fill_nulls_with_0) OVER ( PARTITION BY - subq_10.metric_time__week - , subq_10.booking__ds__month - ORDER BY subq_10.metric_time__day + subq_9.metric_time__week + , subq_9.booking__ds__month + ORDER BY subq_9.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.metric_time__day - , subq_9.metric_time__week - , subq_9.booking__ds__month - , COALESCE(subq_9.bookers, 0) AS every_two_days_bookers_fill_nulls_with_0 + subq_8.metric_time__day + , subq_8.metric_time__week + , subq_8.booking__ds__month + , COALESCE(subq_8.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 - , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week - , subq_6.booking__ds__month AS booking__ds__month - , subq_6.bookers AS bookers + subq_6.metric_time__day AS metric_time__day + , DATE_TRUNC('week', subq_6.metric_time__day) AS metric_time__week + , subq_5.booking__ds__month AS booking__ds__month + , subq_5.bookers AS bookers FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_7.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_5.booking__ds__month - , subq_5.metric_time__day - , subq_5.metric_time__week - , COUNT(DISTINCT subq_5.bookers) AS bookers + subq_4.booking__ds__month + , subq_4.metric_time__day + , subq_4.metric_time__week + , COUNT(DISTINCT subq_4.bookers) AS bookers FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] SELECT - subq_4.booking__ds__month - , subq_4.metric_time__day - , subq_4.metric_time__week - , subq_4.bookers + subq_2.booking__ds__month AS booking__ds__month + , subq_2.metric_time__day AS metric_time__day + , subq_2.metric_time__week AS metric_time__week + , subq_1.bookers AS bookers FROM ( - -- Join Self Over Time Range + -- Time Spine + SELECT + DATE_TRUNC('month', subq_3.ds) AS booking__ds__month + , subq_3.ds AS metric_time__day + , DATE_TRUNC('week', subq_3.ds) AS metric_time__week + FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('month', subq_3.ds) + , subq_3.ds + , DATE_TRUNC('week', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' SELECT - subq_2.booking__ds__month AS booking__ds__month - , subq_2.metric_time__day AS metric_time__day - , subq_2.metric_time__week AS metric_time__week - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine + -- Read Elements From Semantic Model 'bookings_source' SELECT - DATE_TRUNC('month', subq_3.ds) AS booking__ds__month - , subq_3.ds AS metric_time__day - , DATE_TRUNC('week', subq_3.ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - , subq_3.ds - , DATE_TRUNC('week', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day - ) - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day + ) + ) subq_4 GROUP BY - subq_5.booking__ds__month - , subq_5.metric_time__day - , subq_5.metric_time__week - ) subq_6 + subq_4.booking__ds__month + , subq_4.metric_time__day + , subq_4.metric_time__week + ) subq_5 ON - subq_7.metric_time__day = subq_6.metric_time__day - ) subq_9 - ) subq_10 -) subq_11 + subq_6.metric_time__day = subq_5.metric_time__day + ) subq_8 + ) subq_9 +) subq_10 GROUP BY - subq_11.metric_time__week - , subq_11.booking__ds__month - , subq_11.every_two_days_bookers_fill_nulls_with_0 + subq_10.metric_time__week + , subq_10.booking__ds__month + , subq_10.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 d2e2b91c1d..ae078487d7 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 @@ -19,19 +19,19 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_20.ds AS metric_time__day - , DATE_TRUNC('week', subq_20.ds) AS metric_time__week - , subq_18.booking__ds__month AS booking__ds__month - , subq_18.bookers AS bookers - FROM ***************************.mf_time_spine subq_20 + subq_18.ds AS metric_time__day + , DATE_TRUNC('week', subq_18.ds) AS metric_time__week + , subq_16.booking__ds__month AS booking__ds__month + , subq_16.bookers AS bookers + FROM ***************************.mf_time_spine subq_18 LEFT OUTER JOIN ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__week', 'booking__ds__month', 'metric_time__day'] -- Aggregate Measures SELECT - subq_14.booking__ds__month AS booking__ds__month - , subq_14.metric_time__day AS metric_time__day - , subq_14.metric_time__week AS metric_time__week + subq_13.booking__ds__month AS booking__ds__month + , subq_13.metric_time__day AS metric_time__day + , subq_13.metric_time__week AS metric_time__week , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers FROM ( -- Time Spine @@ -39,29 +39,29 @@ FROM ( DATE_TRUNC('month', ds) AS booking__ds__month , ds AS metric_time__day , DATE_TRUNC('week', ds) AS metric_time__week - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_14 GROUP BY DATE_TRUNC('month', ds) , ds , DATE_TRUNC('week', ds) - ) subq_14 + ) subq_13 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_14.metric_time__day + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_13.metric_time__day ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_14.metric_time__day - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_13.metric_time__day - INTERVAL 2 day ) GROUP BY - subq_14.booking__ds__month - , subq_14.metric_time__day - , subq_14.metric_time__week - ) subq_18 + subq_13.booking__ds__month + , subq_13.metric_time__day + , subq_13.metric_time__week + ) subq_16 ON - subq_20.ds = subq_18.metric_time__day - ) subq_21 -) subq_23 + subq_18.ds = subq_16.metric_time__day + ) subq_19 +) subq_21 GROUP BY metric_time__week , booking__ds__month diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_custom_granularity__plan0.sql index 702792fa53..c369f760a6 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_custom_granularity__plan0.sql @@ -1,164 +1,125 @@ -- Re-aggregate Metric via Group By SELECT - subq_9.metric_time__martian_day - , subq_9.trailing_2_months_revenue + subq_8.metric_time__martian_day + , subq_8.trailing_2_months_revenue FROM ( -- Window Function for Metric Re-aggregation SELECT - subq_8.metric_time__martian_day - , AVG(subq_8.trailing_2_months_revenue) OVER (PARTITION BY subq_8.metric_time__martian_day) AS trailing_2_months_revenue + subq_7.metric_time__martian_day + , AVG(subq_7.trailing_2_months_revenue) OVER (PARTITION BY subq_7.metric_time__martian_day) AS trailing_2_months_revenue FROM ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__martian_day - , subq_7.metric_time__day - , subq_7.txn_revenue AS trailing_2_months_revenue + subq_6.metric_time__martian_day + , subq_6.metric_time__day + , subq_6.txn_revenue AS trailing_2_months_revenue FROM ( -- Aggregate Measures SELECT - subq_6.metric_time__martian_day - , subq_6.metric_time__day - , SUM(subq_6.txn_revenue) AS txn_revenue + subq_5.metric_time__martian_day + , subq_5.metric_time__day + , SUM(subq_5.txn_revenue) AS txn_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__day', 'metric_time__day'] -- Join to Custom Granularity Dataset SELECT - subq_4.metric_time__day AS metric_time__day - , subq_4.txn_revenue AS txn_revenue - , subq_5.martian_day AS metric_time__martian_day + subq_2.metric_time__day AS metric_time__day + , subq_1.txn_revenue AS txn_revenue + , subq_4.martian_day AS metric_time__martian_day FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.revenue_instance__ds__day AS revenue_instance__ds__day - , subq_1.revenue_instance__ds__week AS revenue_instance__ds__week - , subq_1.revenue_instance__ds__month AS revenue_instance__ds__month - , subq_1.revenue_instance__ds__quarter AS revenue_instance__ds__quarter - , subq_1.revenue_instance__ds__year AS revenue_instance__ds__year - , subq_1.revenue_instance__ds__extract_year AS revenue_instance__ds__extract_year - , subq_1.revenue_instance__ds__extract_quarter AS revenue_instance__ds__extract_quarter - , subq_1.revenue_instance__ds__extract_month AS revenue_instance__ds__extract_month - , subq_1.revenue_instance__ds__extract_day AS revenue_instance__ds__extract_day - , subq_1.revenue_instance__ds__extract_dow AS revenue_instance__ds__extract_dow - , subq_1.revenue_instance__ds__extract_doy AS revenue_instance__ds__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.user AS user - , subq_1.revenue_instance__user AS revenue_instance__user - , subq_1.txn_revenue AS txn_revenue + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.revenue_instance__ds__day + , subq_0.revenue_instance__ds__week + , subq_0.revenue_instance__ds__month + , subq_0.revenue_instance__ds__quarter + , subq_0.revenue_instance__ds__year + , subq_0.revenue_instance__ds__extract_year + , subq_0.revenue_instance__ds__extract_quarter + , subq_0.revenue_instance__ds__extract_month + , subq_0.revenue_instance__ds__extract_day + , subq_0.revenue_instance__ds__extract_dow + , subq_0.revenue_instance__ds__extract_doy + , subq_0.ds__day AS metric_time__day + , subq_0.ds__week AS metric_time__week + , subq_0.ds__month AS metric_time__month + , subq_0.ds__quarter AS metric_time__quarter + , subq_0.ds__year AS metric_time__year + , subq_0.ds__extract_year AS metric_time__extract_year + , subq_0.ds__extract_quarter AS metric_time__extract_quarter + , subq_0.ds__extract_month AS metric_time__extract_month + , subq_0.ds__extract_day AS metric_time__extract_day + , subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.ds__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.revenue_instance__user + , subq_0.txn_revenue FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'revenue' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.revenue_instance__ds__day - , subq_0.revenue_instance__ds__week - , subq_0.revenue_instance__ds__month - , subq_0.revenue_instance__ds__quarter - , subq_0.revenue_instance__ds__year - , subq_0.revenue_instance__ds__extract_year - , subq_0.revenue_instance__ds__extract_quarter - , subq_0.revenue_instance__ds__extract_month - , subq_0.revenue_instance__ds__extract_day - , subq_0.revenue_instance__ds__extract_dow - , subq_0.revenue_instance__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.revenue_instance__user - , subq_0.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month - ) - ) subq_4 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 month + ) LEFT OUTER JOIN - ***************************.mf_time_spine subq_5 + ***************************.mf_time_spine subq_4 ON - subq_4.metric_time__day = subq_5.ds - ) subq_6 + subq_2.metric_time__day = subq_4.ds + ) subq_5 GROUP BY - subq_6.metric_time__martian_day - , subq_6.metric_time__day - ) subq_7 - ) subq_8 -) subq_9 + subq_5.metric_time__martian_day + , subq_5.metric_time__day + ) subq_6 + ) subq_7 +) subq_8 GROUP BY - subq_9.metric_time__martian_day - , subq_9.trailing_2_months_revenue + subq_8.metric_time__martian_day + , subq_8.trailing_2_months_revenue diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_custom_granularity__plan0_optimized.sql index 731247315b..ee410c20d3 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_custom_granularity__plan0_optimized.sql @@ -9,37 +9,32 @@ FROM ( metric_time__martian_day , AVG(txn_revenue) OVER (PARTITION BY metric_time__martian_day) AS trailing_2_months_revenue FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['txn_revenue', 'metric_time__day', 'metric_time__day'] -- Join to Custom Granularity Dataset -- Aggregate Measures SELECT - subq_15.martian_day AS metric_time__martian_day - , subq_14.metric_time__day AS metric_time__day - , SUM(subq_14.txn_revenue) AS txn_revenue - FROM ( - -- Join Self Over Time Range - SELECT - subq_13.ds AS metric_time__day - , revenue_src_28000.revenue AS txn_revenue - FROM ***************************.mf_time_spine subq_13 - INNER JOIN - ***************************.fct_revenue revenue_src_28000 - ON - ( - DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_13.ds - ) AND ( - DATE_TRUNC('day', revenue_src_28000.created_at) > subq_13.ds - INTERVAL 2 month - ) - ) subq_14 + subq_13.martian_day AS metric_time__martian_day + , subq_12.ds AS metric_time__day + , SUM(revenue_src_28000.revenue) AS txn_revenue + FROM ***************************.mf_time_spine subq_12 + INNER JOIN + ***************************.fct_revenue revenue_src_28000 + ON + ( + DATE_TRUNC('day', revenue_src_28000.created_at) <= subq_12.ds + ) AND ( + DATE_TRUNC('day', revenue_src_28000.created_at) > subq_12.ds - INTERVAL 2 month + ) LEFT OUTER JOIN - ***************************.mf_time_spine subq_15 + ***************************.mf_time_spine subq_13 ON - subq_14.metric_time__day = subq_15.ds + subq_12.ds = subq_13.ds GROUP BY - subq_15.martian_day - , subq_14.metric_time__day - ) subq_17 -) subq_19 + subq_13.martian_day + , subq_12.ds + ) subq_15 +) subq_17 GROUP BY metric_time__martian_day , trailing_2_months_revenue diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_derived_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_derived_metric_with_custom_granularity__plan0.sql index 5e1a1c349e..8f220d3253 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_derived_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_derived_metric_with_custom_granularity__plan0.sql @@ -1,469 +1,251 @@ -- Compute Metrics via Expressions SELECT - subq_14.booking__ds__martian_day + subq_10.booking__ds__martian_day , booking_value * 0.05 / bookers AS booking_fees_per_booker FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.booking__ds__martian_day, subq_13.booking__ds__martian_day) AS booking__ds__martian_day - , MAX(subq_6.booking_value) AS booking_value - , MAX(subq_13.bookers) AS bookers + COALESCE(subq_4.booking__ds__martian_day, subq_9.booking__ds__martian_day) AS booking__ds__martian_day + , MAX(subq_4.booking_value) AS booking_value + , MAX(subq_9.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_5.booking__ds__martian_day - , subq_5.booking_value + subq_3.booking__ds__martian_day + , subq_3.booking_value FROM ( -- Aggregate Measures SELECT - subq_4.booking__ds__martian_day - , SUM(subq_4.booking_value) AS booking_value + subq_2.booking__ds__martian_day + , SUM(subq_2.booking_value) AS booking_value FROM ( + -- Join to Custom Granularity Dataset -- Pass Only Elements: ['booking_value', 'booking__ds__martian_day'] SELECT - subq_3.booking__ds__martian_day - , subq_3.booking_value + subq_0.booking_value AS booking_value + , subq_1.martian_day AS booking__ds__martian_day FROM ( - -- Pass Only Elements: ['booking_value', 'booking__ds__day'] - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking_value AS booking_value - , subq_2.martian_day AS booking__ds__martian_day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_2 - ON - subq_1.booking__ds__day = subq_2.ds - ) subq_3 - ) subq_4 + 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.booking__ds__day = subq_1.ds + ) subq_2 GROUP BY - subq_4.booking__ds__martian_day - ) subq_5 - ) subq_6 + subq_2.booking__ds__martian_day + ) subq_3 + ) subq_4 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_12.booking__ds__martian_day - , subq_12.bookers + subq_8.booking__ds__martian_day + , subq_8.bookers FROM ( -- Aggregate Measures SELECT - subq_11.booking__ds__martian_day - , COUNT(DISTINCT subq_11.bookers) AS bookers + subq_7.booking__ds__martian_day + , COUNT(DISTINCT subq_7.bookers) AS bookers FROM ( + -- Join to Custom Granularity Dataset -- Pass Only Elements: ['bookers', 'booking__ds__martian_day'] SELECT - subq_10.booking__ds__martian_day - , subq_10.bookers + subq_5.bookers AS bookers + , subq_6.martian_day AS booking__ds__martian_day FROM ( - -- Pass Only Elements: ['bookers', 'booking__ds__day'] - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_8.booking__ds__day AS booking__ds__day - , subq_8.bookers AS bookers - , subq_9.martian_day AS booking__ds__martian_day - 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.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.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.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 - 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_7 - ) subq_8 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 - ON - subq_8.booking__ds__day = subq_9.ds - ) subq_10 - ) subq_11 + 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_5 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_6 + ON + subq_5.booking__ds__day = subq_6.ds + ) subq_7 GROUP BY - subq_11.booking__ds__martian_day - ) subq_12 - ) subq_13 + subq_7.booking__ds__martian_day + ) subq_8 + ) subq_9 ON - subq_6.booking__ds__martian_day = subq_13.booking__ds__martian_day + subq_4.booking__ds__martian_day = subq_9.booking__ds__martian_day GROUP BY - COALESCE(subq_6.booking__ds__martian_day, subq_13.booking__ds__martian_day) -) subq_14 + COALESCE(subq_4.booking__ds__martian_day, subq_9.booking__ds__martian_day) +) subq_10 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_derived_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_derived_metric_with_custom_granularity__plan0_optimized.sql index 3bc3f746f5..fd420cadb4 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_derived_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_derived_metric_with_custom_granularity__plan0_optimized.sql @@ -3,20 +3,19 @@ SELECT booking__ds__martian_day , booking_value * 0.05 / bookers AS booking_fees_per_booker FROM ( - -- Pass Only Elements: ['booking_value', 'bookers', 'booking__ds__day'] -- Join to Custom Granularity Dataset -- Pass Only Elements: ['booking_value', 'bookers', 'booking__ds__martian_day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.martian_day AS booking__ds__martian_day + subq_12.martian_day AS booking__ds__martian_day , SUM(bookings_source_src_28000.booking_value) AS booking_value , COUNT(DISTINCT bookings_source_src_28000.guest_id) AS bookers FROM ***************************.fct_bookings bookings_source_src_28000 LEFT OUTER JOIN - ***************************.mf_time_spine subq_17 + ***************************.mf_time_spine subq_12 ON - DATE_TRUNC('day', bookings_source_src_28000.ds) = subq_17.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) = subq_12.ds GROUP BY - subq_17.martian_day -) subq_21 + subq_12.martian_day +) subq_15 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index bc46bbc2a8..5f158e58f0 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -1,167 +1,88 @@ -- Compute Metrics via Expressions SELECT - subq_5.metric_time__martian_day - , subq_5.listing__ds__month - , subq_5.listings + subq_3.metric_time__martian_day + , subq_3.listing__ds__month + , subq_3.listings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__martian_day - , subq_4.listing__ds__month - , SUM(subq_4.listings) AS listings + subq_2.metric_time__martian_day + , subq_2.listing__ds__month + , SUM(subq_2.listings) AS listings FROM ( + -- Join to Custom Granularity Dataset -- Pass Only Elements: ['listings', 'metric_time__martian_day', 'listing__ds__month'] SELECT - subq_3.metric_time__martian_day - , subq_3.listing__ds__month - , subq_3.listings + subq_0.listing__ds__month AS listing__ds__month + , subq_0.listings AS listings + , subq_1.martian_day AS metric_time__martian_day FROM ( - -- Pass Only Elements: ['listings', 'metric_time__day', 'listing__ds__month'] - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_1.listing__ds__month AS listing__ds__month - , subq_1.metric_time__day AS metric_time__day - , subq_1.listings AS listings - , subq_2.martian_day AS metric_time__martian_day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_2 - ON - subq_1.metric_time__day = subq_2.ds - ) subq_3 - ) subq_4 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 + ON + subq_0.ds__day = subq_1.ds + ) subq_2 GROUP BY - subq_4.metric_time__martian_day - , subq_4.listing__ds__month -) subq_5 + subq_2.metric_time__martian_day + , subq_2.listing__ds__month +) subq_3 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index 2f45574e41..cc1f0e89e4 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -1,25 +1,23 @@ --- Pass Only Elements: ['listings', 'metric_time__day', 'listing__ds__month'] -- Join to Custom Granularity Dataset -- Pass Only Elements: ['listings', 'metric_time__martian_day', 'listing__ds__month'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_8.martian_day AS metric_time__martian_day - , subq_7.listing__ds__month AS listing__ds__month - , SUM(subq_7.listings) AS listings + subq_5.martian_day AS metric_time__martian_day + , subq_4.listing__ds__month AS listing__ds__month + , SUM(subq_4.listings) AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' - -- Metric Time Dimension 'ds' SELECT - DATE_TRUNC('month', created_at) AS listing__ds__month - , DATE_TRUNC('day', created_at) AS metric_time__day - , 1 AS listings + 1 AS listings + , DATE_TRUNC('day', created_at) AS ds__day + , DATE_TRUNC('month', created_at) AS listing__ds__month FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_7 +) subq_4 LEFT OUTER JOIN - ***************************.mf_time_spine subq_8 + ***************************.mf_time_spine subq_5 ON - subq_7.metric_time__day = subq_8.ds + subq_4.ds__day = subq_5.ds GROUP BY - subq_8.martian_day - , subq_7.listing__ds__month + subq_5.martian_day + , subq_4.listing__ds__month diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_multiple_metrics_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_multiple_metrics_with_custom_granularity__plan0.sql index 5059d9a939..9af479eda3 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_multiple_metrics_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_multiple_metrics_with_custom_granularity__plan0.sql @@ -1,400 +1,213 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__martian_day, subq_13.metric_time__martian_day) AS metric_time__martian_day - , MAX(subq_6.bookings) AS bookings - , MAX(subq_13.listings) AS listings + COALESCE(subq_4.metric_time__martian_day, subq_9.metric_time__martian_day) AS metric_time__martian_day + , MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__martian_day - , subq_5.bookings + subq_3.metric_time__martian_day + , subq_3.bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__martian_day - , SUM(subq_4.bookings) AS bookings + subq_2.metric_time__martian_day + , SUM(subq_2.bookings) AS bookings FROM ( + -- Join to Custom Granularity Dataset -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] SELECT - subq_3.metric_time__martian_day - , subq_3.bookings + subq_0.bookings AS bookings + , subq_1.martian_day AS metric_time__martian_day FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day'] - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.metric_time__day AS metric_time__day - , subq_1.bookings AS bookings - , subq_2.martian_day AS metric_time__martian_day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_2 - ON - subq_1.metric_time__day = subq_2.ds - ) subq_3 - ) subq_4 + 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 GROUP BY - subq_4.metric_time__martian_day - ) subq_5 -) subq_6 + subq_2.metric_time__martian_day + ) subq_3 +) subq_4 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_12.metric_time__martian_day - , subq_12.listings + subq_8.metric_time__martian_day + , subq_8.listings FROM ( -- Aggregate Measures SELECT - subq_11.metric_time__martian_day - , SUM(subq_11.listings) AS listings + subq_7.metric_time__martian_day + , SUM(subq_7.listings) AS listings FROM ( + -- Join to Custom Granularity Dataset -- Pass Only Elements: ['listings', 'metric_time__martian_day'] SELECT - subq_10.metric_time__martian_day - , subq_10.listings + subq_5.listings AS listings + , subq_6.martian_day AS metric_time__martian_day FROM ( - -- Pass Only Elements: ['listings', 'metric_time__day'] - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_8.metric_time__day AS metric_time__day - , subq_8.listings AS listings - , subq_9.martian_day AS metric_time__martian_day - 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.created_at__day - , subq_7.created_at__week - , subq_7.created_at__month - , subq_7.created_at__quarter - , subq_7.created_at__year - , subq_7.created_at__extract_year - , subq_7.created_at__extract_quarter - , subq_7.created_at__extract_month - , subq_7.created_at__extract_day - , subq_7.created_at__extract_dow - , subq_7.created_at__extract_doy - , subq_7.listing__ds__day - , subq_7.listing__ds__week - , subq_7.listing__ds__month - , subq_7.listing__ds__quarter - , subq_7.listing__ds__year - , subq_7.listing__ds__extract_year - , subq_7.listing__ds__extract_quarter - , subq_7.listing__ds__extract_month - , subq_7.listing__ds__extract_day - , subq_7.listing__ds__extract_dow - , subq_7.listing__ds__extract_doy - , subq_7.listing__created_at__day - , subq_7.listing__created_at__week - , subq_7.listing__created_at__month - , subq_7.listing__created_at__quarter - , subq_7.listing__created_at__year - , subq_7.listing__created_at__extract_year - , subq_7.listing__created_at__extract_quarter - , subq_7.listing__created_at__extract_month - , subq_7.listing__created_at__extract_day - , subq_7.listing__created_at__extract_dow - , subq_7.listing__created_at__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.listing - , subq_7.user - , subq_7.listing__user - , subq_7.country_latest - , subq_7.is_lux_latest - , subq_7.capacity_latest - , subq_7.listing__country_latest - , subq_7.listing__is_lux_latest - , subq_7.listing__capacity_latest - , subq_7.listings - , subq_7.largest_listing - , subq_7.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_7 - ) subq_8 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 - ON - subq_8.metric_time__day = subq_9.ds - ) subq_10 - ) subq_11 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_5 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_6 + ON + subq_5.ds__day = subq_6.ds + ) subq_7 GROUP BY - subq_11.metric_time__martian_day - ) subq_12 -) subq_13 + subq_7.metric_time__martian_day + ) subq_8 +) subq_9 ON - subq_6.metric_time__martian_day = subq_13.metric_time__martian_day + subq_4.metric_time__martian_day = subq_9.metric_time__martian_day GROUP BY - COALESCE(subq_6.metric_time__martian_day, subq_13.metric_time__martian_day) + COALESCE(subq_4.metric_time__martian_day, subq_9.metric_time__martian_day) diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_multiple_metrics_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_multiple_metrics_with_custom_granularity__plan0_optimized.sql index e5b55102e9..2222a501a2 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_multiple_metrics_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_multiple_metrics_with_custom_granularity__plan0_optimized.sql @@ -1,57 +1,53 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_20.metric_time__martian_day, subq_27.metric_time__martian_day) AS metric_time__martian_day - , MAX(subq_20.bookings) AS bookings - , MAX(subq_27.listings) AS listings + COALESCE(subq_14.metric_time__martian_day, subq_19.metric_time__martian_day) AS metric_time__martian_day + , MAX(subq_14.bookings) AS bookings + , MAX(subq_19.listings) AS listings FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Join to Custom Granularity Dataset -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_16.martian_day AS metric_time__martian_day - , SUM(subq_15.bookings) AS bookings + subq_11.martian_day AS metric_time__martian_day + , SUM(subq_10.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , 1 AS bookings + 1 AS bookings + , DATE_TRUNC('day', ds) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + ) subq_10 LEFT OUTER JOIN - ***************************.mf_time_spine subq_16 + ***************************.mf_time_spine subq_11 ON - subq_15.metric_time__day = subq_16.ds + subq_10.ds__day = subq_11.ds GROUP BY - subq_16.martian_day -) subq_20 + subq_11.martian_day +) subq_14 FULL OUTER JOIN ( - -- Pass Only Elements: ['listings', 'metric_time__day'] -- Join to Custom Granularity Dataset -- Pass Only Elements: ['listings', 'metric_time__martian_day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_23.martian_day AS metric_time__martian_day - , SUM(subq_22.listings) AS listings + subq_16.martian_day AS metric_time__martian_day + , SUM(subq_15.listings) AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' - -- Metric Time Dimension 'ds' SELECT - DATE_TRUNC('day', created_at) AS metric_time__day - , 1 AS listings + 1 AS listings + , DATE_TRUNC('day', created_at) AS ds__day FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_22 + ) subq_15 LEFT OUTER JOIN - ***************************.mf_time_spine subq_23 + ***************************.mf_time_spine subq_16 ON - subq_22.metric_time__day = subq_23.ds + subq_15.ds__day = subq_16.ds GROUP BY - subq_23.martian_day -) subq_27 + subq_16.martian_day +) subq_19 ON - subq_20.metric_time__martian_day = subq_27.metric_time__martian_day + subq_14.metric_time__martian_day = subq_19.metric_time__martian_day GROUP BY - COALESCE(subq_20.metric_time__martian_day, subq_27.metric_time__martian_day) + COALESCE(subq_14.metric_time__martian_day, subq_19.metric_time__martian_day) diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql index 5cf61b70ac..1530968cd8 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0.sql @@ -1,441 +1,227 @@ +-- Join to Custom Granularity Dataset -- Pass Only Elements: ['metric_time__day', 'metric_time__martian_day', 'user__bio_added_ts__martian_day', 'user__bio_added_ts__month'] SELECT - subq_6.user__bio_added_ts__martian_day - , subq_6.metric_time__martian_day - , subq_6.user__bio_added_ts__month - , subq_6.metric_time__day + subq_0.user__bio_added_ts__month AS user__bio_added_ts__month + , subq_2.metric_time__day AS metric_time__day + , subq_3.martian_day AS metric_time__martian_day + , subq_4.martian_day AS user__bio_added_ts__martian_day FROM ( - -- Join Standard Outputs - -- Join to Custom Granularity Dataset - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'users_ds_source' 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.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__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.last_profile_edit_ts__millisecond AS last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second AS last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute AS last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour AS last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day AS last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week AS last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month AS last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter AS last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year AS last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year AS last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter AS last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month AS last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day AS last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow AS last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy AS last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second AS bio_added_ts__second - , subq_0.bio_added_ts__minute AS bio_added_ts__minute - , subq_0.bio_added_ts__hour AS bio_added_ts__hour - , subq_0.bio_added_ts__day AS bio_added_ts__day - , subq_0.bio_added_ts__week AS bio_added_ts__week - , subq_0.bio_added_ts__month AS bio_added_ts__month - , subq_0.bio_added_ts__quarter AS bio_added_ts__quarter - , subq_0.bio_added_ts__year AS bio_added_ts__year - , subq_0.bio_added_ts__extract_year AS bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter AS bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month AS bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day AS bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow AS bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy AS bio_added_ts__extract_doy - , subq_0.last_login_ts__minute AS last_login_ts__minute - , subq_0.last_login_ts__hour AS last_login_ts__hour - , subq_0.last_login_ts__day AS last_login_ts__day - , subq_0.last_login_ts__week AS last_login_ts__week - , subq_0.last_login_ts__month AS last_login_ts__month - , subq_0.last_login_ts__quarter AS last_login_ts__quarter - , subq_0.last_login_ts__year AS last_login_ts__year - , subq_0.last_login_ts__extract_year AS last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter AS last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month AS last_login_ts__extract_month - , subq_0.last_login_ts__extract_day AS last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow AS last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy AS last_login_ts__extract_doy - , subq_0.archived_at__hour AS archived_at__hour - , subq_0.archived_at__day AS archived_at__day - , subq_0.archived_at__week AS archived_at__week - , subq_0.archived_at__month AS archived_at__month - , subq_0.archived_at__quarter AS archived_at__quarter - , subq_0.archived_at__year AS archived_at__year - , subq_0.archived_at__extract_year AS archived_at__extract_year - , subq_0.archived_at__extract_quarter AS archived_at__extract_quarter - , subq_0.archived_at__extract_month AS archived_at__extract_month - , subq_0.archived_at__extract_day AS archived_at__extract_day - , subq_0.archived_at__extract_dow AS archived_at__extract_dow - , subq_0.archived_at__extract_doy AS archived_at__extract_doy - , subq_0.user__ds__day AS user__ds__day - , subq_0.user__ds__week AS user__ds__week - , subq_0.user__ds__month AS user__ds__month - , subq_0.user__ds__quarter AS user__ds__quarter - , subq_0.user__ds__year AS user__ds__year - , subq_0.user__ds__extract_year AS user__ds__extract_year - , subq_0.user__ds__extract_quarter AS user__ds__extract_quarter - , subq_0.user__ds__extract_month AS user__ds__extract_month - , subq_0.user__ds__extract_day AS user__ds__extract_day - , subq_0.user__ds__extract_dow AS user__ds__extract_dow - , subq_0.user__ds__extract_doy AS user__ds__extract_doy - , subq_0.user__created_at__day AS user__created_at__day - , subq_0.user__created_at__week AS user__created_at__week - , subq_0.user__created_at__month AS user__created_at__month - , subq_0.user__created_at__quarter AS user__created_at__quarter - , subq_0.user__created_at__year AS user__created_at__year - , subq_0.user__created_at__extract_year AS user__created_at__extract_year - , subq_0.user__created_at__extract_quarter AS user__created_at__extract_quarter - , subq_0.user__created_at__extract_month AS user__created_at__extract_month - , subq_0.user__created_at__extract_day AS user__created_at__extract_day - , subq_0.user__created_at__extract_dow AS user__created_at__extract_dow - , subq_0.user__created_at__extract_doy AS user__created_at__extract_doy - , subq_0.user__ds_partitioned__day AS user__ds_partitioned__day - , subq_0.user__ds_partitioned__week AS user__ds_partitioned__week - , subq_0.user__ds_partitioned__month AS user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter AS user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year AS user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year AS user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter AS user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month AS user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day AS user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow AS user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy AS user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond AS user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second AS user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute AS user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour AS user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day AS user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week AS user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month AS user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter AS user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year AS user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year AS user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter AS user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month AS user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day AS user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow AS user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy AS user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second AS user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute AS user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour AS user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day AS user__bio_added_ts__day - , subq_0.user__bio_added_ts__week AS user__bio_added_ts__week - , subq_0.user__bio_added_ts__month AS user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter AS user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year AS user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year AS user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter AS user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month AS user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day AS user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow AS user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy AS user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute AS user__last_login_ts__minute - , subq_0.user__last_login_ts__hour AS user__last_login_ts__hour - , subq_0.user__last_login_ts__day AS user__last_login_ts__day - , subq_0.user__last_login_ts__week AS user__last_login_ts__week - , subq_0.user__last_login_ts__month AS user__last_login_ts__month - , subq_0.user__last_login_ts__quarter AS user__last_login_ts__quarter - , subq_0.user__last_login_ts__year AS user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year AS user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter AS user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month AS user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day AS user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow AS user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy AS user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour AS user__archived_at__hour - , subq_0.user__archived_at__day AS user__archived_at__day - , subq_0.user__archived_at__week AS user__archived_at__week - , subq_0.user__archived_at__month AS user__archived_at__month - , subq_0.user__archived_at__quarter AS user__archived_at__quarter - , subq_0.user__archived_at__year AS user__archived_at__year - , subq_0.user__archived_at__extract_year AS user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter AS user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month AS user__archived_at__extract_month - , subq_0.user__archived_at__extract_day AS user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow AS user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy AS user__archived_at__extract_doy - , subq_3.metric_time__day AS metric_time__day - , subq_0.user AS user - , subq_0.home_state AS home_state - , subq_0.user__home_state AS user__home_state - , subq_0.new_users AS new_users - , subq_0.archived_users AS archived_users - , subq_4.martian_day AS metric_time__martian_day - , subq_5.martian_day AS user__bio_added_ts__martian_day + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 +) subq_0 +CROSS JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_1.ds__day AS metric_time__day FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - CROSS JOIN ( - -- Pass Only Elements: ['metric_time__day',] + -- Time Spine SELECT - subq_2.metric_time__day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.ds__martian_day - , subq_1.ds__day AS metric_time__day - , subq_1.ds__week AS metric_time__week - , subq_1.ds__month AS metric_time__month - , subq_1.ds__quarter AS metric_time__quarter - , subq_1.ds__year AS metric_time__year - , subq_1.ds__extract_year AS metric_time__extract_year - , subq_1.ds__extract_quarter AS metric_time__extract_quarter - , subq_1.ds__extract_month AS metric_time__extract_month - , subq_1.ds__extract_day AS metric_time__extract_day - , subq_1.ds__extract_dow AS metric_time__extract_dow - , subq_1.ds__extract_doy AS metric_time__extract_doy - , subq_1.ds__martian_day AS metric_time__martian_day - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day - , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week - , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month - , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter - , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year - , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year - , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter - , EXTRACT(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_1 - ) subq_2 - ) subq_3 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_4 - ON - subq_3.metric_time__day = subq_4.ds - LEFT OUTER JOIN - ***************************.mf_time_spine subq_5 - ON - subq_0.user__bio_added_ts__day = subq_5.ds -) subq_6 + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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_1 +) subq_2 +LEFT OUTER JOIN + ***************************.mf_time_spine subq_3 +ON + subq_2.metric_time__day = subq_3.ds +LEFT OUTER JOIN + ***************************.mf_time_spine subq_4 +ON + subq_0.user__bio_added_ts__day = subq_4.ds GROUP BY - subq_6.user__bio_added_ts__martian_day - , subq_6.metric_time__martian_day - , subq_6.user__bio_added_ts__month - , subq_6.metric_time__day + subq_0.user__bio_added_ts__month + , subq_2.metric_time__day + , subq_3.martian_day + , subq_4.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql index f4cb2ff0cf..539699032d 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_joined_to_non_default_grain__plan0_optimized.sql @@ -1,25 +1,23 @@ --- Join Standard Outputs --- Join to Custom Granularity Dataset -- Join to Custom Granularity Dataset -- Pass Only Elements: ['metric_time__day', 'metric_time__martian_day', 'user__bio_added_ts__martian_day', 'user__bio_added_ts__month'] SELECT - subq_12.martian_day AS user__bio_added_ts__martian_day - , subq_11.martian_day AS metric_time__martian_day - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month , DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day + , subq_8.martian_day AS metric_time__martian_day + , subq_9.martian_day AS user__bio_added_ts__martian_day FROM ***************************.dim_users users_ds_source_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN - ***************************.mf_time_spine subq_11 + ***************************.mf_time_spine subq_8 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_11.ds + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_8.ds LEFT OUTER JOIN - ***************************.mf_time_spine subq_12 + ***************************.mf_time_spine subq_9 ON - DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) = subq_12.ds + DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) = subq_9.ds GROUP BY - subq_12.martian_day - , subq_11.martian_day - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) + DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) , DATE_TRUNC('day', time_spine_src_28006.ds) + , subq_8.martian_day + , subq_9.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_metric_time__plan0.sql index 48672d84f6..dc85f714b9 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_metric_time__plan0.sql @@ -1,56 +1,29 @@ +-- Join to Custom Granularity Dataset -- Pass Only Elements: ['metric_time__martian_day',] SELECT - subq_2.metric_time__martian_day + subq_0.ds__martian_day AS metric_time__martian_day + , subq_1.martian_day AS metric_time__martian_day FROM ( - -- Metric Time Dimension 'ds' - -- Join to Custom Granularity Dataset + -- Time Spine 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__martian_day AS ds__martian_day - , 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.ds__martian_day AS metric_time__martian_day - , subq_1.martian_day AS metric_time__martian_day - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day - , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week - , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month - , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter - , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year - , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year - , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter - , EXTRACT(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_0 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_1 - ON - subq_0.ds__day = subq_1.ds -) subq_2 + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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_0 +LEFT OUTER JOIN + ***************************.mf_time_spine subq_1 +ON + subq_0.ds__day = subq_1.ds GROUP BY - subq_2.metric_time__martian_day + subq_0.ds__martian_day + , subq_1.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql index cb56b24088..1908ff154a 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_metric_time__plan0_optimized.sql @@ -1,12 +1,13 @@ --- Metric Time Dimension 'ds' -- Join to Custom Granularity Dataset -- Pass Only Elements: ['metric_time__martian_day',] SELECT - subq_4.martian_day AS metric_time__martian_day + time_spine_src_28006.martian_day AS metric_time__martian_day + , subq_3.martian_day AS metric_time__martian_day FROM ***************************.mf_time_spine time_spine_src_28006 LEFT OUTER JOIN - ***************************.mf_time_spine subq_4 + ***************************.mf_time_spine subq_3 ON - DATE_TRUNC('day', time_spine_src_28006.ds) = subq_4.ds + DATE_TRUNC('day', time_spine_src_28006.ds) = subq_3.ds GROUP BY - subq_4.martian_day + time_spine_src_28006.martian_day + , subq_3.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_non_metric_time__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_non_metric_time__plan0.sql index 7d3bcb3d0c..7d4fe8fed2 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_non_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_non_metric_time__plan0.sql @@ -1,104 +1,11 @@ +-- Join to Custom Granularity Dataset -- Pass Only Elements: ['booking__ds__martian_day',] SELECT - subq_1.booking__ds__martian_day -FROM ( - -- Read Elements From Semantic Model 'bookings_source' - -- Join to Custom Granularity Dataset - SELECT - 1 AS bookings - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings - , bookings_source_src_28000.booking_value AS 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 AS 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 - , subq_0.martian_day AS booking__ds__martian_day - FROM ***************************.fct_bookings bookings_source_src_28000 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_0 - ON - DATE_TRUNC('day', bookings_source_src_28000.ds) = subq_0.ds -) subq_1 + subq_0.martian_day AS booking__ds__martian_day +FROM ***************************.fct_bookings bookings_source_src_28000 +LEFT OUTER JOIN + ***************************.mf_time_spine subq_0 +ON + DATE_TRUNC('day', bookings_source_src_28000.ds) = subq_0.ds GROUP BY - subq_1.booking__ds__martian_day + subq_0.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_non_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_non_metric_time__plan0_optimized.sql index d800e789e7..c5600be808 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_non_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metric_custom_granularity_non_metric_time__plan0_optimized.sql @@ -1,12 +1,11 @@ --- Read Elements From Semantic Model 'bookings_source' -- Join to Custom Granularity Dataset -- Pass Only Elements: ['booking__ds__martian_day',] SELECT - subq_2.martian_day AS booking__ds__martian_day + subq_1.martian_day AS booking__ds__martian_day FROM ***************************.fct_bookings bookings_source_src_28000 LEFT OUTER JOIN - ***************************.mf_time_spine subq_2 + ***************************.mf_time_spine subq_1 ON - DATE_TRUNC('day', bookings_source_src_28000.ds) = subq_2.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) = subq_1.ds GROUP BY - subq_2.martian_day + subq_1.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_filter__plan0.sql index 05a7977e3d..b64e2fc466 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_filter__plan0.sql @@ -1,134 +1,74 @@ +-- Constrain Output with WHERE -- Pass Only Elements: ['listing__ds__day',] SELECT - subq_2.listing__ds__day + subq_1.listing__ds__day FROM ( - -- Constrain Output with WHERE + -- Read Elements From Semantic Model 'listings_latest' + -- Join to Custom Granularity Dataset SELECT - subq_1.listing__ds__martian_day - , subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.created_at__day - , subq_1.created_at__week - , subq_1.created_at__month - , subq_1.created_at__quarter - , subq_1.created_at__year - , subq_1.created_at__extract_year - , subq_1.created_at__extract_quarter - , subq_1.created_at__extract_month - , subq_1.created_at__extract_day - , subq_1.created_at__extract_dow - , subq_1.created_at__extract_doy - , subq_1.listing__ds__day - , subq_1.listing__ds__week - , subq_1.listing__ds__month - , subq_1.listing__ds__quarter - , subq_1.listing__ds__year - , subq_1.listing__ds__extract_year - , subq_1.listing__ds__extract_quarter - , subq_1.listing__ds__extract_month - , subq_1.listing__ds__extract_day - , subq_1.listing__ds__extract_dow - , subq_1.listing__ds__extract_doy - , subq_1.listing__created_at__day - , subq_1.listing__created_at__week - , subq_1.listing__created_at__month - , subq_1.listing__created_at__quarter - , subq_1.listing__created_at__year - , subq_1.listing__created_at__extract_year - , subq_1.listing__created_at__extract_quarter - , subq_1.listing__created_at__extract_month - , subq_1.listing__created_at__extract_day - , subq_1.listing__created_at__extract_dow - , subq_1.listing__created_at__extract_doy - , subq_1.listing - , subq_1.user - , subq_1.listing__user - , subq_1.country_latest - , subq_1.is_lux_latest - , subq_1.capacity_latest - , subq_1.listing__country_latest - , subq_1.listing__is_lux_latest - , subq_1.listing__capacity_latest - , subq_1.listings - , subq_1.largest_listing - , subq_1.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - -- Join to Custom Granularity Dataset - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - , subq_0.martian_day AS listing__ds__martian_day - FROM ***************************.dim_listings_latest listings_latest_src_28000 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_0 - ON - DATE_TRUNC('day', listings_latest_src_28000.created_at) = subq_0.ds - ) subq_1 - WHERE listing__ds__martian_day = '2020-01-01' -) subq_2 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + , subq_0.martian_day AS listing__ds__martian_day + FROM ***************************.dim_listings_latest listings_latest_src_28000 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_0 + ON + DATE_TRUNC('day', listings_latest_src_28000.created_at) = subq_0.ds +) subq_1 +WHERE listing__ds__martian_day = '2020-01-01' GROUP BY - subq_2.listing__ds__day + subq_1.listing__ds__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_filter__plan0_optimized.sql index bce724a864..60dd283f05 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_filter__plan0_optimized.sql @@ -7,13 +7,13 @@ FROM ( -- Join to Custom Granularity Dataset SELECT DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , subq_3.martian_day AS listing__ds__martian_day + , subq_2.martian_day AS listing__ds__martian_day FROM ***************************.dim_listings_latest listings_latest_src_28000 LEFT OUTER JOIN - ***************************.mf_time_spine subq_3 + ***************************.mf_time_spine subq_2 ON - DATE_TRUNC('day', listings_latest_src_28000.created_at) = subq_3.ds -) subq_4 + DATE_TRUNC('day', listings_latest_src_28000.created_at) = subq_2.ds +) subq_3 WHERE listing__ds__martian_day = '2020-01-01' GROUP BY listing__ds__day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_in_filter_and_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_in_filter_and_group_by__plan0.sql index 062e6d8cbe..fa2b215511 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_in_filter_and_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_in_filter_and_group_by__plan0.sql @@ -1,134 +1,74 @@ +-- Constrain Output with WHERE -- Pass Only Elements: ['listing__ds__martian_day',] SELECT - subq_2.listing__ds__martian_day + subq_1.listing__ds__martian_day FROM ( - -- Constrain Output with WHERE + -- Read Elements From Semantic Model 'listings_latest' + -- Join to Custom Granularity Dataset SELECT - subq_1.listing__ds__martian_day - , subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.created_at__day - , subq_1.created_at__week - , subq_1.created_at__month - , subq_1.created_at__quarter - , subq_1.created_at__year - , subq_1.created_at__extract_year - , subq_1.created_at__extract_quarter - , subq_1.created_at__extract_month - , subq_1.created_at__extract_day - , subq_1.created_at__extract_dow - , subq_1.created_at__extract_doy - , subq_1.listing__ds__day - , subq_1.listing__ds__week - , subq_1.listing__ds__month - , subq_1.listing__ds__quarter - , subq_1.listing__ds__year - , subq_1.listing__ds__extract_year - , subq_1.listing__ds__extract_quarter - , subq_1.listing__ds__extract_month - , subq_1.listing__ds__extract_day - , subq_1.listing__ds__extract_dow - , subq_1.listing__ds__extract_doy - , subq_1.listing__created_at__day - , subq_1.listing__created_at__week - , subq_1.listing__created_at__month - , subq_1.listing__created_at__quarter - , subq_1.listing__created_at__year - , subq_1.listing__created_at__extract_year - , subq_1.listing__created_at__extract_quarter - , subq_1.listing__created_at__extract_month - , subq_1.listing__created_at__extract_day - , subq_1.listing__created_at__extract_dow - , subq_1.listing__created_at__extract_doy - , subq_1.listing - , subq_1.user - , subq_1.listing__user - , subq_1.country_latest - , subq_1.is_lux_latest - , subq_1.capacity_latest - , subq_1.listing__country_latest - , subq_1.listing__is_lux_latest - , subq_1.listing__capacity_latest - , subq_1.listings - , subq_1.largest_listing - , subq_1.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - -- Join to Custom Granularity Dataset - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , listings_latest_src_28000.user_id AS user - , listings_latest_src_28000.user_id AS listing__user - , subq_0.martian_day AS listing__ds__martian_day - FROM ***************************.dim_listings_latest listings_latest_src_28000 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_0 - ON - DATE_TRUNC('day', listings_latest_src_28000.created_at) = subq_0.ds - ) subq_1 - WHERE listing__ds__martian_day = '2020-01-01' -) subq_2 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , listings_latest_src_28000.user_id AS user + , listings_latest_src_28000.user_id AS listing__user + , subq_0.martian_day AS listing__ds__martian_day + FROM ***************************.dim_listings_latest listings_latest_src_28000 + LEFT OUTER JOIN + ***************************.mf_time_spine subq_0 + ON + DATE_TRUNC('day', listings_latest_src_28000.created_at) = subq_0.ds +) subq_1 +WHERE listing__ds__martian_day = '2020-01-01' GROUP BY - subq_2.listing__ds__martian_day + subq_1.listing__ds__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_in_filter_and_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_in_filter_and_group_by__plan0_optimized.sql index 3dd32191d6..f5ac97bc4a 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_in_filter_and_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_no_metrics_with_custom_granularity_in_filter_and_group_by__plan0_optimized.sql @@ -6,13 +6,13 @@ FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Join to Custom Granularity Dataset SELECT - subq_3.martian_day AS listing__ds__martian_day + subq_2.martian_day AS listing__ds__martian_day FROM ***************************.dim_listings_latest listings_latest_src_28000 LEFT OUTER JOIN - ***************************.mf_time_spine subq_3 + ***************************.mf_time_spine subq_2 ON - DATE_TRUNC('day', listings_latest_src_28000.created_at) = subq_3.ds -) subq_4 + DATE_TRUNC('day', listings_latest_src_28000.created_at) = subq_2.ds +) subq_3 WHERE listing__ds__martian_day = '2020-01-01' GROUP BY listing__ds__martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity__plan0.sql index 5b7bb60efa..c4bad0f209 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity__plan0.sql @@ -1,225 +1,116 @@ -- Compute Metrics via Expressions SELECT - subq_5.booking__ds__martian_day - , subq_5.bookings + subq_3.booking__ds__martian_day + , subq_3.bookings FROM ( -- Aggregate Measures SELECT - subq_4.booking__ds__martian_day - , SUM(subq_4.bookings) AS bookings + subq_2.booking__ds__martian_day + , SUM(subq_2.bookings) AS bookings FROM ( + -- Join to Custom Granularity Dataset -- Pass Only Elements: ['bookings', 'booking__ds__martian_day'] SELECT - subq_3.booking__ds__martian_day - , subq_3.bookings + subq_0.bookings AS bookings + , subq_1.martian_day AS booking__ds__martian_day FROM ( - -- Pass Only Elements: ['bookings', 'booking__ds__day'] - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.booking__ds__day AS booking__ds__day - , subq_1.bookings AS bookings - , subq_2.martian_day AS booking__ds__martian_day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_2 - ON - subq_1.booking__ds__day = subq_2.ds - ) subq_3 - ) subq_4 + 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.booking__ds__day = subq_1.ds + ) subq_2 GROUP BY - subq_4.booking__ds__martian_day -) subq_5 + subq_2.booking__ds__martian_day +) subq_3 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity__plan0_optimized.sql index fade916c75..008663ca9f 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity__plan0_optimized.sql @@ -1,22 +1,20 @@ --- Pass Only Elements: ['bookings', 'booking__ds__day'] -- Join to Custom Granularity Dataset -- Pass Only Elements: ['bookings', 'booking__ds__martian_day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_8.martian_day AS booking__ds__martian_day - , SUM(subq_7.bookings) AS bookings + subq_5.martian_day AS booking__ds__martian_day + , SUM(subq_4.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' SELECT - DATE_TRUNC('day', ds) AS booking__ds__day - , 1 AS bookings + 1 AS bookings + , DATE_TRUNC('day', ds) AS booking__ds__day FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_7 +) subq_4 LEFT OUTER JOIN - ***************************.mf_time_spine subq_8 + ***************************.mf_time_spine subq_5 ON - subq_7.booking__ds__day = subq_8.ds + subq_4.booking__ds__day = subq_5.ds GROUP BY - subq_8.martian_day + subq_5.martian_day diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_filter__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_filter__plan0.sql index d6197e5be1..c19375d906 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_filter__plan0.sql @@ -1,228 +1,121 @@ -- Compute Metrics via Expressions SELECT - subq_6.bookings + subq_4.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_5.bookings) AS bookings + SUM(subq_3.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] SELECT - subq_4.bookings + subq_2.bookings FROM ( - -- Constrain Output with WHERE + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Join to Custom Granularity Dataset SELECT - subq_3.metric_time__martian_day - , subq_3.metric_time__day - , subq_3.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings AS bookings + , subq_1.martian_day AS metric_time__martian_day FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day'] - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.metric_time__day AS metric_time__day - , subq_1.bookings AS bookings - , subq_2.martian_day AS metric_time__martian_day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_2 - ON - subq_1.metric_time__day = subq_2.ds - ) subq_3 - WHERE metric_time__martian_day = '2020-01-01' - ) subq_4 - ) subq_5 -) subq_6 + 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 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_filter__plan0_optimized.sql index 28f1b6995f..fb3f7b1cc2 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_filter__plan0_optimized.sql @@ -5,22 +5,22 @@ SELECT SUM(bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Join to Custom Granularity Dataset SELECT - subq_8.bookings AS bookings - , subq_9.martian_day AS metric_time__martian_day + subq_5.bookings AS bookings + , subq_6.martian_day AS metric_time__martian_day FROM ( -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , 1 AS bookings + 1 AS bookings + , DATE_TRUNC('day', ds) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 + ) subq_5 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_6 ON - subq_8.metric_time__day = subq_9.ds -) subq_10 + subq_5.ds__day = subq_6.ds +) subq_7 WHERE metric_time__martian_day = '2020-01-01' diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_in_filter_and_group_by__plan0.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_in_filter_and_group_by__plan0.sql index 07df220f23..a21a1a308c 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_in_filter_and_group_by__plan0.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_in_filter_and_group_by__plan0.sql @@ -1,233 +1,126 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__martian_day - , subq_6.bookings + subq_4.metric_time__martian_day + , subq_4.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__martian_day - , SUM(subq_5.bookings) AS bookings + subq_3.metric_time__martian_day + , SUM(subq_3.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__martian_day'] SELECT - subq_4.metric_time__martian_day - , subq_4.bookings + subq_2.metric_time__martian_day + , subq_2.bookings FROM ( - -- Constrain Output with WHERE + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day'] + -- Join to Custom Granularity Dataset SELECT - subq_3.metric_time__martian_day - , subq_3.metric_time__day - , subq_3.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings AS bookings + , subq_1.martian_day AS metric_time__martian_day FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day'] - -- Join to Custom Granularity Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.metric_time__day AS metric_time__day - , subq_1.bookings AS bookings - , subq_2.martian_day AS metric_time__martian_day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - LEFT OUTER JOIN - ***************************.mf_time_spine subq_2 - ON - subq_1.metric_time__day = subq_2.ds - ) subq_3 - WHERE metric_time__martian_day = '2020-01-01' - ) subq_4 - ) subq_5 + 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 GROUP BY - subq_5.metric_time__martian_day -) subq_6 + subq_3.metric_time__martian_day +) subq_4 diff --git a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_in_filter_and_group_by__plan0_optimized.sql b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_in_filter_and_group_by__plan0_optimized.sql index 8c1f6de498..fc388c1d55 100644 --- a/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_in_filter_and_group_by__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_custom_granularity.py/SqlQueryPlan/DuckDB/test_simple_metric_with_custom_granularity_in_filter_and_group_by__plan0_optimized.sql @@ -6,24 +6,24 @@ SELECT metric_time__martian_day , SUM(bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Join to Custom Granularity Dataset SELECT - subq_8.bookings AS bookings - , subq_9.martian_day AS metric_time__martian_day + subq_5.bookings AS bookings + , subq_6.martian_day AS metric_time__martian_day FROM ( -- Read Elements From Semantic Model 'bookings_source' - -- Metric Time Dimension 'ds' SELECT - DATE_TRUNC('day', ds) AS metric_time__day - , 1 AS bookings + 1 AS bookings + , DATE_TRUNC('day', ds) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 + ) subq_5 LEFT OUTER JOIN - ***************************.mf_time_spine subq_9 + ***************************.mf_time_spine subq_6 ON - subq_8.metric_time__day = subq_9.ds -) subq_10 + subq_5.ds__day = subq_6.ds +) subq_7 WHERE metric_time__martian_day = '2020-01-01' GROUP BY metric_time__martian_day diff --git a/tests_metricflow/snapshots/test_data_warehouse_tasks.py/str/DuckDB/test_build_metric_tasks__query0.sql b/tests_metricflow/snapshots/test_data_warehouse_tasks.py/str/DuckDB/test_build_metric_tasks__query0.sql index f705fe3237..84f93bd7e6 100644 --- a/tests_metricflow/snapshots/test_data_warehouse_tasks.py/str/DuckDB/test_build_metric_tasks__query0.sql +++ b/tests_metricflow/snapshots/test_data_warehouse_tasks.py/str/DuckDB/test_build_metric_tasks__query0.sql @@ -6,6 +6,6 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS count_dogs FROM ***************************.fct_animals animals_src_10000 -) subq_2 +) subq_1 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_data_warehouse_tasks.py/str/DuckDB/test_build_saved_query_tasks__query0.sql b/tests_metricflow/snapshots/test_data_warehouse_tasks.py/str/DuckDB/test_build_saved_query_tasks__query0.sql index d76ce501d3..0ba7edfa5f 100644 --- a/tests_metricflow/snapshots/test_data_warehouse_tasks.py/str/DuckDB/test_build_saved_query_tasks__query0.sql +++ b/tests_metricflow/snapshots/test_data_warehouse_tasks.py/str/DuckDB/test_build_saved_query_tasks__query0.sql @@ -5,10 +5,9 @@ SELECT , SUM(instant_bookings) AS instant_bookings FROM ( SELECT - subq_2.metric_time__day AS metric_time__day - , listings_latest_src_10000.capacity AS listing__capacity_latest - , subq_2.bookings AS bookings - , subq_2.instant_bookings AS instant_bookings + subq_1.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings + , subq_1.instant_bookings AS instant_bookings FROM ( SELECT DATE_TRUNC('day', ds) AS metric_time__day @@ -16,12 +15,12 @@ FROM ( , 1 AS bookings , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings FROM ***************************.fct_bookings bookings_source_src_10000 - ) subq_2 + ) subq_1 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_10000 ON - subq_2.listing = listings_latest_src_10000.listing_id -) subq_7 + subq_1.listing = listings_latest_src_10000.listing_id +) subq_4 WHERE listing__capacity_latest > 3 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_combined_metrics_plan__ep_0.xml b/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_combined_metrics_plan__ep_0.xml index 16ed0e7902..d731f27397 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_combined_metrics_plan__ep_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_combined_metrics_plan__ep_0.xml @@ -5,11 +5,11 @@ - - - - - + + + + + @@ -26,11 +26,11 @@ - + - + @@ -47,16 +47,16 @@ - + - + - + - + @@ -72,15 +72,15 @@ - + - + - + - - + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_joined_plan__ep_0.xml b/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_joined_plan__ep_0.xml index f231dbcccd..c818e60c9d 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_joined_plan__ep_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_joined_plan__ep_0.xml @@ -8,9 +8,9 @@ - - - + + + @@ -20,13 +20,13 @@ - + - + - - + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_multihop_joined_plan__ep_0.xml b/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_multihop_joined_plan__ep_0.xml index 11c8105735..f6b94496a7 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_multihop_joined_plan__ep_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_multihop_joined_plan__ep_0.xml @@ -8,7 +8,7 @@ - + @@ -17,7 +17,6 @@ - @@ -28,14 +27,14 @@ - + - + - + - + diff --git a/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_small_combined_metrics_plan__ep_0.xml b/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_small_combined_metrics_plan__ep_0.xml index 38ff24ffce..80dae21855 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_small_combined_metrics_plan__ep_0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_execution.py/ExecutionPlan/DuckDB/test_small_combined_metrics_plan__ep_0.xml @@ -5,9 +5,9 @@ - - - + + + @@ -22,10 +22,10 @@ - + - + @@ -38,10 +38,10 @@ - + - + - + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_combine_output_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_combine_output_node__plan0.sql index a8d97dae7f..67a22c742c 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_combine_output_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_combine_output_node__plan0.sql @@ -1,226 +1,44 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_2.is_instant, subq_5.is_instant) AS is_instant - , MAX(subq_2.bookings) AS bookings - , COALESCE(MAX(subq_5.instant_bookings), 1) AS instant_bookings - , COALESCE(MAX(subq_5.bookers), 1) AS bookers + COALESCE(subq_1.is_instant, subq_3.is_instant) AS is_instant + , MAX(subq_1.bookings) AS bookings + , COALESCE(MAX(subq_3.instant_bookings), 1) AS instant_bookings + , COALESCE(MAX(subq_3.bookers), 1) AS bookers FROM ( -- Aggregate Measures SELECT - subq_1.is_instant - , SUM(subq_1.bookings) AS bookings + subq_0.is_instant + , SUM(subq_0.bookings) AS bookings FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'is_instant'] SELECT - subq_0.is_instant - , subq_0.bookings - 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 - ) subq_1 + 1 AS bookings + , bookings_source_src_28000.is_instant + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 GROUP BY - subq_1.is_instant -) subq_2 + subq_0.is_instant +) subq_1 FULL OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.is_instant - , SUM(subq_4.instant_bookings) AS instant_bookings - , COUNT(DISTINCT subq_4.bookers) AS bookers + subq_2.is_instant + , SUM(subq_2.instant_bookings) AS instant_bookings + , COUNT(DISTINCT subq_2.bookers) AS bookers FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['instant_bookings', 'bookers', 'is_instant'] SELECT - subq_3.is_instant - , subq_3.instant_bookings - , subq_3.bookers - 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_3 - ) subq_4 + CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.is_instant + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_2 GROUP BY - subq_4.is_instant -) subq_5 + subq_2.is_instant +) subq_3 ON - subq_2.is_instant = subq_5.is_instant + subq_1.is_instant = subq_3.is_instant GROUP BY - COALESCE(subq_2.is_instant, subq_5.is_instant) + COALESCE(subq_1.is_instant, subq_3.is_instant) diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_combine_output_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_combine_output_node__plan0_optimized.sql index ad81788114..513c432a1a 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_combine_output_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_combine_output_node__plan0_optimized.sql @@ -1,25 +1,25 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_8.is_instant, subq_11.is_instant) AS is_instant - , MAX(subq_8.bookings) AS bookings - , COALESCE(MAX(subq_11.instant_bookings), 1) AS instant_bookings - , COALESCE(MAX(subq_11.bookers), 1) AS bookers + COALESCE(subq_5.is_instant, subq_7.is_instant) AS is_instant + , MAX(subq_5.bookings) AS bookings + , COALESCE(MAX(subq_7.instant_bookings), 1) AS instant_bookings + , COALESCE(MAX(subq_7.bookers), 1) AS bookers FROM ( -- Aggregate Measures SELECT is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'is_instant'] SELECT - is_instant - , 1 AS bookings + 1 AS bookings + , is_instant FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_7 + ) subq_4 GROUP BY is_instant -) subq_8 +) subq_5 FULL OUTER JOIN ( -- Aggregate Measures SELECT @@ -27,18 +27,18 @@ FULL OUTER JOIN ( , SUM(instant_bookings) AS instant_bookings , COUNT(DISTINCT bookers) AS bookers FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['instant_bookings', 'bookers', 'is_instant'] SELECT - is_instant - , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings , guest_id AS bookers + , is_instant FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_10 + ) subq_6 GROUP BY is_instant -) subq_11 +) subq_7 ON - subq_8.is_instant = subq_11.is_instant + subq_5.is_instant = subq_7.is_instant GROUP BY - COALESCE(subq_8.is_instant, subq_11.is_instant) + COALESCE(subq_5.is_instant, subq_7.is_instant) diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node__plan0.sql index 08fdfa6034..2a5d04204d 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node__plan0.sql @@ -1,190 +1,40 @@ -- Compute Metrics via Expressions SELECT - subq_5.listing - , subq_5.listing__country_latest - , subq_5.bookings + subq_3.listing + , subq_3.listing__country_latest + , subq_3.bookings FROM ( -- Aggregate Measures SELECT - subq_4.listing - , subq_4.listing__country_latest - , SUM(subq_4.bookings) AS bookings + subq_2.listing + , subq_2.listing__country_latest + , SUM(subq_2.bookings) AS bookings FROM ( -- Join Standard Outputs SELECT - subq_1.listing AS listing - , subq_3.country_latest AS listing__country_latest - , subq_1.bookings AS bookings + subq_0.listing AS listing + , subq_1.country_latest AS listing__country_latest + , subq_0.bookings AS bookings FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'listing'] SELECT - subq_0.listing - , subq_0.bookings - 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 - ) subq_1 + 1 AS bookings + , bookings_source_src_28000.listing_id AS listing + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_2.listing - , subq_2.country_latest - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_2 - ) subq_3 + listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.listing_id AS listing + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_1 ON - subq_1.listing = subq_3.listing - ) subq_4 + subq_0.listing = subq_1.listing + ) subq_2 GROUP BY - subq_4.listing - , subq_4.listing__country_latest -) subq_5 + subq_2.listing + , subq_2.listing__country_latest +) subq_3 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node__plan0_optimized.sql index 5ebe7177e8..bcd7a485fe 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node__plan0_optimized.sql @@ -2,21 +2,21 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_7.listing AS listing + subq_4.listing AS listing , listings_latest_src_28000.country AS listing__country_latest - , SUM(subq_7.bookings) AS bookings + , SUM(subq_4.bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'listing'] SELECT - listing_id AS listing - , 1 AS bookings + 1 AS bookings + , listing_id AS listing FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_7 +) subq_4 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_7.listing = listings_latest_src_28000.listing_id + subq_4.listing = listings_latest_src_28000.listing_id GROUP BY - subq_7.listing + subq_4.listing , listings_latest_src_28000.country diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql index d37cd06bd3..1fdf23220c 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.sql @@ -1,693 +1,373 @@ -- Compute Metrics via Expressions SELECT - subq_20.ds__day - , subq_20.listing__country_latest - , CAST(subq_20.bookings AS DOUBLE) / CAST(NULLIF(subq_20.views, 0) AS DOUBLE) AS bookings_per_view + subq_14.ds__day + , subq_14.listing__country_latest + , CAST(subq_14.bookings AS DOUBLE) / CAST(NULLIF(subq_14.views, 0) AS DOUBLE) AS bookings_per_view FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_9.ds__day, subq_19.ds__day) AS ds__day - , COALESCE(subq_9.listing__country_latest, subq_19.listing__country_latest) AS listing__country_latest - , MAX(subq_9.bookings) AS bookings - , MAX(subq_19.views) AS views + COALESCE(subq_6.ds__day, subq_13.ds__day) AS ds__day + , COALESCE(subq_6.listing__country_latest, subq_13.listing__country_latest) AS listing__country_latest + , MAX(subq_6.bookings) AS bookings + , MAX(subq_13.views) AS views FROM ( -- Compute Metrics via Expressions SELECT - subq_8.ds__day - , subq_8.listing__country_latest - , subq_8.bookings + subq_5.ds__day + , subq_5.listing__country_latest + , subq_5.bookings FROM ( -- Aggregate Measures SELECT - subq_7.ds__day - , subq_7.listing__country_latest - , SUM(subq_7.bookings) AS bookings + subq_4.ds__day + , subq_4.listing__country_latest + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'ds__day'] SELECT - subq_6.ds__day - , subq_6.listing__country_latest - , subq_6.bookings + subq_1.ds__day AS ds__day + , subq_1.bookings AS bookings FROM ( - -- Join Standard Outputs + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'ds__day', 'listing'] SELECT - subq_2.ds__day AS ds__day - , subq_2.listing AS listing - , subq_5.country_latest AS listing__country_latest - , subq_2.bookings AS bookings + subq_0.ds__day + , subq_0.listing + , subq_0.bookings FROM ( - -- Pass Only Elements: ['bookings', 'ds__day', 'listing'] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.ds__day - , subq_1.listing - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_2.listing + , subq_2.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_4.listing - , subq_4.country_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 GROUP BY - subq_7.ds__day - , subq_7.listing__country_latest - ) subq_8 - ) subq_9 + subq_4.ds__day + , subq_4.listing__country_latest + ) subq_5 + ) subq_6 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_18.ds__day - , subq_18.listing__country_latest - , subq_18.views + subq_12.ds__day + , subq_12.listing__country_latest + , subq_12.views FROM ( -- Aggregate Measures SELECT - subq_17.ds__day - , subq_17.listing__country_latest - , SUM(subq_17.views) AS views + subq_11.ds__day + , subq_11.listing__country_latest + , SUM(subq_11.views) AS views FROM ( + -- Join Standard Outputs -- Pass Only Elements: ['views', 'listing__country_latest', 'ds__day'] SELECT - subq_16.ds__day - , subq_16.listing__country_latest - , subq_16.views + subq_8.ds__day AS ds__day + , subq_8.views AS views FROM ( - -- Join Standard Outputs + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['views', 'ds__day', 'listing'] SELECT - subq_12.ds__day AS ds__day - , subq_12.listing AS listing - , subq_15.country_latest AS listing__country_latest - , subq_12.views AS views + subq_7.ds__day + , subq_7.listing + , subq_7.views FROM ( - -- Pass Only Elements: ['views', 'ds__day', 'listing'] + -- Read Elements From Semantic Model 'views_source' SELECT - subq_11.ds__day - , subq_11.listing - , subq_11.views - 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_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.view__ds__day - , subq_10.view__ds__week - , subq_10.view__ds__month - , subq_10.view__ds__quarter - , subq_10.view__ds__year - , subq_10.view__ds__extract_year - , subq_10.view__ds__extract_quarter - , subq_10.view__ds__extract_month - , subq_10.view__ds__extract_day - , subq_10.view__ds__extract_dow - , subq_10.view__ds__extract_doy - , subq_10.view__ds_partitioned__day - , subq_10.view__ds_partitioned__week - , subq_10.view__ds_partitioned__month - , subq_10.view__ds_partitioned__quarter - , subq_10.view__ds_partitioned__year - , subq_10.view__ds_partitioned__extract_year - , subq_10.view__ds_partitioned__extract_quarter - , subq_10.view__ds_partitioned__extract_month - , subq_10.view__ds_partitioned__extract_day - , subq_10.view__ds_partitioned__extract_dow - , subq_10.view__ds_partitioned__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.user - , subq_10.view__listing - , subq_10.view__user - , subq_10.views - FROM ( - -- Read Elements From Semantic Model 'views_source' - SELECT - 1 AS views - , DATE_TRUNC('day', views_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', views_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', views_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', views_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', views_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM views_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM views_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds) AS view__ds__day - , DATE_TRUNC('week', views_source_src_28000.ds) AS view__ds__week - , DATE_TRUNC('month', views_source_src_28000.ds) AS view__ds__month - , DATE_TRUNC('quarter', views_source_src_28000.ds) AS view__ds__quarter - , DATE_TRUNC('year', views_source_src_28000.ds) AS view__ds__year - , EXTRACT(year FROM views_source_src_28000.ds) AS view__ds__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds) AS view__ds__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds) AS view__ds__extract_month - , EXTRACT(day FROM views_source_src_28000.ds) AS view__ds__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds) AS view__ds__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds) AS view__ds__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__day - , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__week - , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__year - , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_doy - , views_source_src_28000.listing_id AS listing - , views_source_src_28000.user_id AS user - , views_source_src_28000.listing_id AS view__listing - , views_source_src_28000.user_id AS view__user - FROM ***************************.fct_views views_source_src_28000 - ) subq_10 - ) subq_11 - ) subq_12 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] + 1 AS views + , DATE_TRUNC('day', views_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', views_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', views_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', views_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', views_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM views_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM views_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds) AS view__ds__day + , DATE_TRUNC('week', views_source_src_28000.ds) AS view__ds__week + , DATE_TRUNC('month', views_source_src_28000.ds) AS view__ds__month + , DATE_TRUNC('quarter', views_source_src_28000.ds) AS view__ds__quarter + , DATE_TRUNC('year', views_source_src_28000.ds) AS view__ds__year + , EXTRACT(year FROM views_source_src_28000.ds) AS view__ds__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds) AS view__ds__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds) AS view__ds__extract_month + , EXTRACT(day FROM views_source_src_28000.ds) AS view__ds__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds) AS view__ds__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds) AS view__ds__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__day + , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__week + , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__year + , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_doy + , views_source_src_28000.listing_id AS listing + , views_source_src_28000.user_id AS user + , views_source_src_28000.listing_id AS view__listing + , views_source_src_28000.user_id AS view__user + FROM ***************************.fct_views views_source_src_28000 + ) subq_7 + ) subq_8 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_9.listing + , subq_9.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_14.listing - , subq_14.country_latest - FROM ( - -- 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.created_at__day - , subq_13.created_at__week - , subq_13.created_at__month - , subq_13.created_at__quarter - , subq_13.created_at__year - , subq_13.created_at__extract_year - , subq_13.created_at__extract_quarter - , subq_13.created_at__extract_month - , subq_13.created_at__extract_day - , subq_13.created_at__extract_dow - , subq_13.created_at__extract_doy - , subq_13.listing__ds__day - , subq_13.listing__ds__week - , subq_13.listing__ds__month - , subq_13.listing__ds__quarter - , subq_13.listing__ds__year - , subq_13.listing__ds__extract_year - , subq_13.listing__ds__extract_quarter - , subq_13.listing__ds__extract_month - , subq_13.listing__ds__extract_day - , subq_13.listing__ds__extract_dow - , subq_13.listing__ds__extract_doy - , subq_13.listing__created_at__day - , subq_13.listing__created_at__week - , subq_13.listing__created_at__month - , subq_13.listing__created_at__quarter - , subq_13.listing__created_at__year - , subq_13.listing__created_at__extract_year - , subq_13.listing__created_at__extract_quarter - , subq_13.listing__created_at__extract_month - , subq_13.listing__created_at__extract_day - , subq_13.listing__created_at__extract_dow - , subq_13.listing__created_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.user - , subq_13.listing__user - , subq_13.country_latest - , subq_13.is_lux_latest - , subq_13.capacity_latest - , subq_13.listing__country_latest - , subq_13.listing__is_lux_latest - , subq_13.listing__capacity_latest - , subq_13.listings - , subq_13.largest_listing - , subq_13.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_13 - ) subq_14 - ) subq_15 - ON - subq_12.listing = subq_15.listing - ) subq_16 - ) subq_17 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_9 + ) subq_10 + ON + subq_8.listing = subq_10.listing + ) subq_11 GROUP BY - subq_17.ds__day - , subq_17.listing__country_latest - ) subq_18 - ) subq_19 + subq_11.ds__day + , subq_11.listing__country_latest + ) subq_12 + ) subq_13 ON ( - subq_9.listing__country_latest = subq_19.listing__country_latest + subq_6.listing__country_latest = subq_13.listing__country_latest ) AND ( - subq_9.ds__day = subq_19.ds__day + subq_6.ds__day = subq_13.ds__day ) GROUP BY - COALESCE(subq_9.ds__day, subq_19.ds__day) - , COALESCE(subq_9.listing__country_latest, subq_19.listing__country_latest) -) subq_20 + COALESCE(subq_6.ds__day, subq_13.ds__day) + , COALESCE(subq_6.listing__country_latest, subq_13.listing__country_latest) +) subq_14 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql index 67be9580e0..b5fa5d2904 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0_optimized.sql @@ -6,19 +6,19 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_30.ds__day, subq_40.ds__day) AS ds__day - , COALESCE(subq_30.listing__country_latest, subq_40.listing__country_latest) AS listing__country_latest - , MAX(subq_30.bookings) AS bookings - , MAX(subq_40.views) AS views + COALESCE(subq_21.ds__day, subq_28.ds__day) AS ds__day + , COALESCE(subq_21.listing__country_latest, subq_28.listing__country_latest) AS listing__country_latest + , MAX(subq_21.bookings) AS bookings + , MAX(subq_28.views) AS views FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_23.ds__day AS ds__day - , listings_latest_src_28000.country AS listing__country_latest - , SUM(subq_23.bookings) AS bookings + subq_16.ds__day AS ds__day + , subq_19.listing__country_latest AS listing__country_latest + , SUM(subq_16.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -28,24 +28,24 @@ FROM ( , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_23 + ) subq_16 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_23.listing = listings_latest_src_28000.listing_id + subq_16.listing = listings_latest_src_28000.listing_id GROUP BY - subq_23.ds__day - , listings_latest_src_28000.country - ) subq_30 + subq_16.ds__day + , subq_19.listing__country_latest + ) subq_21 FULL OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['views', 'listing__country_latest', 'ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_33.ds__day AS ds__day - , listings_latest_src_28000.country AS listing__country_latest - , SUM(subq_33.views) AS views + subq_23.ds__day AS ds__day + , subq_26.listing__country_latest AS listing__country_latest + , SUM(subq_23.views) AS views FROM ( -- Read Elements From Semantic Model 'views_source' -- Metric Time Dimension 'ds' @@ -55,22 +55,22 @@ FROM ( , listing_id AS listing , 1 AS views FROM ***************************.fct_views views_source_src_28000 - ) subq_33 + ) subq_23 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_33.listing = listings_latest_src_28000.listing_id + subq_23.listing = listings_latest_src_28000.listing_id GROUP BY - subq_33.ds__day - , listings_latest_src_28000.country - ) subq_40 + subq_23.ds__day + , subq_26.listing__country_latest + ) subq_28 ON ( - subq_30.listing__country_latest = subq_40.listing__country_latest + subq_21.listing__country_latest = subq_28.listing__country_latest ) AND ( - subq_30.ds__day = subq_40.ds__day + subq_21.ds__day = subq_28.ds__day ) GROUP BY - COALESCE(subq_30.ds__day, subq_40.ds__day) - , COALESCE(subq_30.listing__country_latest, subq_40.listing__country_latest) -) subq_41 + COALESCE(subq_21.ds__day, subq_28.ds__day) + , COALESCE(subq_21.listing__country_latest, subq_28.listing__country_latest) +) subq_29 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql index c7aabe5705..5697543de4 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.sql @@ -1,193 +1,43 @@ -- Compute Metrics via Expressions SELECT - subq_5.listing - , subq_5.listing__country_latest - , CAST(subq_5.bookings AS DOUBLE) / CAST(NULLIF(subq_5.bookers, 0) AS DOUBLE) AS bookings_per_booker + subq_3.listing + , subq_3.listing__country_latest + , CAST(subq_3.bookings AS DOUBLE) / CAST(NULLIF(subq_3.bookers, 0) AS DOUBLE) AS bookings_per_booker FROM ( -- Aggregate Measures SELECT - subq_4.listing - , subq_4.listing__country_latest - , SUM(subq_4.bookings) AS bookings - , COUNT(DISTINCT subq_4.bookers) AS bookers + subq_2.listing + , subq_2.listing__country_latest + , SUM(subq_2.bookings) AS bookings + , COUNT(DISTINCT subq_2.bookers) AS bookers FROM ( -- Join Standard Outputs SELECT - subq_1.listing AS listing - , subq_3.country_latest AS listing__country_latest - , subq_1.bookings AS bookings - , subq_1.bookers AS bookers + subq_0.listing AS listing + , subq_1.country_latest AS listing__country_latest + , subq_0.bookings AS bookings + , subq_0.bookers AS bookers FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'bookers', 'listing'] SELECT - subq_0.listing - , subq_0.bookings - , subq_0.bookers - 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 - ) subq_1 + 1 AS bookings + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.listing_id AS listing + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_2.listing - , subq_2.country_latest - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_2 - ) subq_3 + listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.listing_id AS listing + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_1 ON - subq_1.listing = subq_3.listing - ) subq_4 + subq_0.listing = subq_1.listing + ) subq_2 GROUP BY - subq_4.listing - , subq_4.listing__country_latest -) subq_5 + subq_2.listing + , subq_2.listing__country_latest +) subq_3 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql index c943b1a8d9..1de01e6374 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_ratio_from_single_semantic_model__plan0_optimized.sql @@ -7,24 +7,24 @@ FROM ( -- Join Standard Outputs -- Aggregate Measures SELECT - subq_7.listing AS listing + subq_4.listing AS listing , listings_latest_src_28000.country AS listing__country_latest - , SUM(subq_7.bookings) AS bookings - , COUNT(DISTINCT subq_7.bookers) AS bookers + , SUM(subq_4.bookings) AS bookings + , COUNT(DISTINCT subq_4.bookers) AS bookers FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'bookers', 'listing'] SELECT - listing_id AS listing - , 1 AS bookings + 1 AS bookings , guest_id AS bookers + , listing_id AS listing FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_7 + ) subq_4 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_7.listing = listings_latest_src_28000.listing_id + subq_4.listing = listings_latest_src_28000.listing_id GROUP BY - subq_7.listing + subq_4.listing , listings_latest_src_28000.country -) subq_11 +) subq_7 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_simple_expr__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_simple_expr__plan0.sql index 069df1629d..4b1b05598b 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_simple_expr__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_simple_expr__plan0.sql @@ -1,190 +1,40 @@ -- Compute Metrics via Expressions SELECT - subq_5.listing - , subq_5.listing__country_latest + subq_3.listing + , subq_3.listing__country_latest , booking_value * 0.05 AS booking_fees FROM ( -- Aggregate Measures SELECT - subq_4.listing - , subq_4.listing__country_latest - , SUM(subq_4.booking_value) AS booking_value + subq_2.listing + , subq_2.listing__country_latest + , SUM(subq_2.booking_value) AS booking_value FROM ( -- Join Standard Outputs SELECT - subq_1.listing AS listing - , subq_3.country_latest AS listing__country_latest - , subq_1.booking_value AS booking_value + subq_0.listing AS listing + , subq_1.country_latest AS listing__country_latest + , subq_0.booking_value AS booking_value FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['booking_value', 'listing'] SELECT - subq_0.listing - , subq_0.booking_value - 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 - ) subq_1 + bookings_source_src_28000.booking_value + , bookings_source_src_28000.listing_id AS listing + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_2.listing - , subq_2.country_latest - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_2 - ) subq_3 + listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.listing_id AS listing + FROM ***************************.dim_listings_latest listings_latest_src_28000 + ) subq_1 ON - subq_1.listing = subq_3.listing - ) subq_4 + subq_0.listing = subq_1.listing + ) subq_2 GROUP BY - subq_4.listing - , subq_4.listing__country_latest -) subq_5 + subq_2.listing + , subq_2.listing__country_latest +) subq_3 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_simple_expr__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_simple_expr__plan0_optimized.sql index 65e701e3dd..d928343ef8 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_simple_expr__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_compute_metrics_node_simple_expr__plan0_optimized.sql @@ -18,4 +18,4 @@ FROM ( GROUP BY bookings_source_src_28000.listing_id , listings_latest_src_28000.country -) subq_11 +) subq_7 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_constrain_time_range_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_constrain_time_range_node__plan0.sql index 5414f95860..8367e55fbc 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_constrain_time_range_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_constrain_time_range_node__plan0.sql @@ -1,112 +1,21 @@ -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] SELECT - subq_2.ds__day - , subq_2.metric_time__day - , subq_2.bookings + subq_1.ds__day + , subq_1.metric_time__day + , subq_1.bookings FROM ( -- Metric Time Dimension 'ds' SELECT - subq_1.ds__day - , subq_1.ds__day AS metric_time__day - , subq_1.bookings + subq_0.ds__day + , subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'ds__day'] SELECT - subq_0.ds__day - , subq_0.bookings - 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 - ) subq_1 -) subq_2 -WHERE subq_2.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' + 1 AS bookings + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 +) subq_1 +WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-02' diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_constrain_time_range_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_constrain_time_range_node__plan0_optimized.sql index d0d15f6943..4e69fd0293 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_constrain_time_range_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_constrain_time_range_node__plan0_optimized.sql @@ -1,4 +1,4 @@ --- Read Elements From Semantic Model 'bookings_source' +-- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'ds__day'] -- Metric Time Dimension 'ds' -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-02T00:00:00] diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimension_with_joined_where_constraint__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimension_with_joined_where_constraint__plan0.sql index ed1028fb88..69197b37ed 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimension_with_joined_where_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimension_with_joined_where_constraint__plan0.sql @@ -1,227 +1,139 @@ +-- Constrain Output with WHERE -- Pass Only Elements: ['user__home_state_latest',] SELECT - subq_4.user__home_state_latest + subq_2.user__home_state_latest FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_1.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' 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.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - FULL OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_1.user - , subq_1.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 - ON - subq_0.user = subq_2.user - ) subq_3 - WHERE listing__country_latest = 'us' -) subq_4 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + FULL OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_1 + ON + subq_0.user = subq_1.user +) subq_2 +WHERE listing__country_latest = 'us' GROUP BY - subq_4.user__home_state_latest + subq_2.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimension_with_joined_where_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimension_with_joined_where_constraint__plan0_optimized.sql index c4e57d3c86..eea51906f8 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimension_with_joined_where_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimension_with_joined_where_constraint__plan0_optimized.sql @@ -12,7 +12,7 @@ FROM ( ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 +) subq_5 WHERE listing__country_latest = 'us' GROUP BY user__home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql index 0962aa9958..f78c43b635 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql @@ -1,167 +1,77 @@ +-- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_3.listing__is_lux_latest - , subq_3.user__home_state_latest + subq_0.listing__is_lux_latest AS listing__is_lux_latest FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' 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.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - FULL OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_1.user - , subq_1.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 - ON - subq_0.user = subq_2.user -) subq_3 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 +FULL OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 +) subq_1 +ON + subq_0.user = subq_1.user GROUP BY - subq_3.listing__is_lux_latest - , subq_3.user__home_state_latest + subq_0.listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql index 96c5d5bb3a..395ae8fe1f 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql @@ -2,7 +2,6 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 @@ -10,4 +9,3 @@ ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY listings_latest_src_28000.is_lux - , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_node__plan0.sql index 4c0230bef5..ee0c252dcd 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_node__plan0.sql @@ -1,96 +1,5 @@ +-- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings',] SELECT - subq_0.bookings -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 + 1 AS bookings +FROM ***************************.fct_bookings bookings_source_src_28000 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_node__plan0_optimized.sql index 554ce484fb..ee0c252dcd 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_node__plan0_optimized.sql @@ -1,4 +1,4 @@ --- Read Elements From Semantic Model 'bookings_source' +-- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings',] SELECT 1 AS bookings diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_node__plan0.sql index 6c7624e9c6..5d646a2c53 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_node__plan0.sql @@ -1,104 +1,13 @@ -- Constrain Output with WHERE SELECT - subq_1.ds__day - , subq_1.bookings + subq_0.ds__day + , subq_0.bookings FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'ds__day'] SELECT - subq_0.ds__day - , subq_0.bookings - 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 -) subq_1 + 1 AS bookings + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + FROM ***************************.fct_bookings bookings_source_src_28000 +) subq_0 WHERE booking__ds__day = '2020-01-01' diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_node__plan0_optimized.sql index 5ee87ba25f..0f7bac29ca 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_node__plan0_optimized.sql @@ -3,11 +3,11 @@ SELECT ds__day , bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'ds__day'] SELECT - DATE_TRUNC('day', ds) AS ds__day - , 1 AS bookings + 1 AS bookings + , DATE_TRUNC('day', ds) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_3 +) subq_1 WHERE booking__ds__day = '2020-01-01' diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql index d1eb9e6cdf..414febe156 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0.sql @@ -1,233 +1,132 @@ -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.listing AS listing - , subq_4.booking_fees AS booking_fees + subq_4.metric_time__day AS metric_time__day + , subq_3.listing AS listing + , subq_3.booking_fees AS booking_fees FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01' -) subq_5 + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + WHERE subq_5.ds BETWEEN '2020-01-01' AND '2021-01-01' +) subq_4 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.listing + subq_2.metric_time__day + , subq_2.listing , booking_value * 0.05 AS booking_fees FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , subq_2.listing - , SUM(subq_2.booking_value) AS booking_value + subq_1.metric_time__day + , subq_1.listing + , SUM(subq_1.booking_value) AS booking_value FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['booking_value', 'metric_time__day', 'listing'] SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.booking_value + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - , subq_2.listing - ) subq_3 -) subq_4 + subq_1.metric_time__day + , subq_1.listing + ) subq_2 +) subq_3 ON - DATE_TRUNC('month', subq_5.metric_time__day) = subq_4.metric_time__day + DATE_TRUNC('month', subq_4.metric_time__day) = subq_3.metric_time__day diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql index 6054b232dc..41ad2712dc 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_to_grain__plan0_optimized.sql @@ -1,15 +1,15 @@ -- Join to Time Spine Dataset SELECT - subq_12.metric_time__day AS metric_time__day - , subq_11.listing AS listing - , subq_11.booking_fees AS booking_fees + subq_10.metric_time__day AS metric_time__day + , subq_9.listing AS listing + , subq_9.booking_fees AS booking_fees FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_11 WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' -) subq_12 +) subq_10 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -29,7 +29,7 @@ INNER JOIN ( GROUP BY DATE_TRUNC('day', ds) , listing_id - ) subq_10 -) subq_11 + ) subq_8 +) subq_9 ON - DATE_TRUNC('month', subq_12.metric_time__day) = subq_11.metric_time__day + DATE_TRUNC('month', subq_10.metric_time__day) = subq_9.metric_time__day diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0.sql index 6556fc936f..c2a0d950d1 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0.sql @@ -1,233 +1,132 @@ -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.listing AS listing - , subq_4.booking_fees AS booking_fees + subq_4.metric_time__day AS metric_time__day + , subq_3.listing AS listing + , subq_3.booking_fees AS booking_fees FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01' -) subq_5 + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + WHERE subq_5.ds BETWEEN '2020-01-01' AND '2021-01-01' +) subq_4 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.listing + subq_2.metric_time__day + , subq_2.listing , booking_value * 0.05 AS booking_fees FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , subq_2.listing - , SUM(subq_2.booking_value) AS booking_value + subq_1.metric_time__day + , subq_1.listing + , SUM(subq_1.booking_value) AS booking_value FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['booking_value', 'metric_time__day', 'listing'] SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.booking_value + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - , subq_2.listing - ) subq_3 -) subq_4 + subq_1.metric_time__day + , subq_1.listing + ) subq_2 +) subq_3 ON - subq_5.metric_time__day - INTERVAL 10 day = subq_4.metric_time__day + subq_4.metric_time__day - INTERVAL 10 day = subq_3.metric_time__day diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql index 836bd707a7..5307124084 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_with_offset_window__plan0_optimized.sql @@ -1,15 +1,15 @@ -- Join to Time Spine Dataset SELECT - subq_12.metric_time__day AS metric_time__day - , subq_11.listing AS listing - , subq_11.booking_fees AS booking_fees + subq_10.metric_time__day AS metric_time__day + , subq_9.listing AS listing + , subq_9.booking_fees AS booking_fees FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_11 WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' -) subq_12 +) subq_10 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -29,7 +29,7 @@ INNER JOIN ( GROUP BY DATE_TRUNC('day', ds) , listing_id - ) subq_10 -) subq_11 + ) subq_8 +) subq_9 ON - subq_12.metric_time__day - INTERVAL 10 day = subq_11.metric_time__day + subq_10.metric_time__day - INTERVAL 10 day = subq_9.metric_time__day diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0.sql index 2c925cc021..fe1da410c1 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0.sql @@ -1,233 +1,132 @@ -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.listing AS listing - , subq_4.booking_fees AS booking_fees + subq_4.metric_time__day AS metric_time__day + , subq_3.listing AS listing + , subq_3.booking_fees AS booking_fees FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - WHERE subq_6.ds BETWEEN '2020-01-01' AND '2021-01-01' -) subq_5 + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + WHERE subq_5.ds BETWEEN '2020-01-01' AND '2021-01-01' +) subq_4 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.listing + subq_2.metric_time__day + , subq_2.listing , booking_value * 0.05 AS booking_fees FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , subq_2.listing - , SUM(subq_2.booking_value) AS booking_value + subq_1.metric_time__day + , subq_1.listing + , SUM(subq_1.booking_value) AS booking_value FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['booking_value', 'metric_time__day', 'listing'] SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.booking_value + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - , subq_2.listing - ) subq_3 -) subq_4 + subq_1.metric_time__day + , subq_1.listing + ) subq_2 +) subq_3 ON - subq_5.metric_time__day = subq_4.metric_time__day + subq_4.metric_time__day = subq_3.metric_time__day diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0_optimized.sql index e4f47734b0..084a328d58 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_join_to_time_spine_node_without_offset__plan0_optimized.sql @@ -1,15 +1,15 @@ -- Join to Time Spine Dataset SELECT - subq_12.metric_time__day AS metric_time__day - , subq_11.listing AS listing - , subq_11.booking_fees AS booking_fees + subq_10.metric_time__day AS metric_time__day + , subq_9.listing AS listing + , subq_9.booking_fees AS booking_fees FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_13 + FROM ***************************.mf_time_spine subq_11 WHERE ds BETWEEN '2020-01-01' AND '2021-01-01' -) subq_12 +) subq_10 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -29,7 +29,7 @@ INNER JOIN ( GROUP BY DATE_TRUNC('day', ds) , listing_id - ) subq_10 -) subq_11 + ) subq_8 +) subq_9 ON - subq_12.metric_time__day = subq_11.metric_time__day + subq_10.metric_time__day = subq_9.metric_time__day diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_measure_aggregation_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_measure_aggregation_node__plan0.sql index d3f9a7fb97..e499984e3c 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_measure_aggregation_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_measure_aggregation_node__plan0.sql @@ -1,107 +1,16 @@ -- Aggregate Measures SELECT - SUM(subq_1.bookings) AS bookings - , SUM(subq_1.instant_bookings) AS instant_bookings - , COUNT(DISTINCT subq_1.bookers) AS bookers - , AVG(subq_1.average_booking_value) AS average_booking_value + SUM(subq_0.bookings) AS bookings + , SUM(subq_0.instant_bookings) AS instant_bookings + , COUNT(DISTINCT subq_0.bookers) AS bookers + , AVG(subq_0.average_booking_value) AS average_booking_value FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'instant_bookings', 'average_booking_value', 'bookers'] SELECT - subq_0.bookings - , subq_0.instant_bookings - , subq_0.bookers - , subq_0.average_booking_value - 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 -) subq_1 + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_28000.guest_id AS bookers + , bookings_source_src_28000.booking_value AS average_booking_value + FROM ***************************.fct_bookings bookings_source_src_28000 +) subq_0 diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_measure_aggregation_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_measure_aggregation_node__plan0_optimized.sql index 6e5528a6c9..8476f523c5 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_measure_aggregation_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_measure_aggregation_node__plan0_optimized.sql @@ -1,4 +1,4 @@ --- Read Elements From Semantic Model 'bookings_source' +-- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'instant_bookings', 'average_booking_value', 'bookers'] -- Aggregate Measures SELECT diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_multi_join_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_multi_join_node__plan0.sql index f3ed9fa304..2196ead1e4 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_multi_join_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_multi_join_node__plan0.sql @@ -1,243 +1,34 @@ -- Join Standard Outputs SELECT - subq_1.listing AS listing - , subq_3.country_latest AS listing__country_latest - , subq_5.country_latest AS listing__country_latest - , subq_1.bookings AS bookings + subq_0.listing AS listing + , subq_1.country_latest AS listing__country_latest + , subq_2.country_latest AS listing__country_latest + , subq_0.bookings AS bookings FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'listing'] SELECT - subq_0.listing - , subq_0.bookings - 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 -) subq_1 + 1 AS bookings + , bookings_source_src_28000.listing_id AS listing + FROM ***************************.fct_bookings bookings_source_src_28000 +) subq_0 LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_2.listing - , subq_2.country_latest - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_2 -) subq_3 + listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.listing_id AS listing + FROM ***************************.dim_listings_latest listings_latest_src_28000 +) subq_1 ON - subq_1.listing = subq_3.listing + subq_0.listing = subq_1.listing LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['country_latest', 'listing'] SELECT - subq_4.listing - , subq_4.country_latest - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_4 -) subq_5 + listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.listing_id AS listing + FROM ***************************.dim_listings_latest listings_latest_src_28000 +) subq_2 ON - subq_1.listing = subq_5.listing + subq_0.listing = subq_2.listing diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_multi_join_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_multi_join_node__plan0_optimized.sql index 7d9c669f54..7c87c96a29 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_multi_join_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_multi_join_node__plan0_optimized.sql @@ -1,34 +1,34 @@ -- Join Standard Outputs SELECT - subq_7.listing AS listing - , subq_9.country_latest AS listing__country_latest - , subq_11.country_latest AS listing__country_latest - , subq_7.bookings AS bookings + subq_3.listing AS listing + , subq_4.country_latest AS listing__country_latest + , subq_5.country_latest AS listing__country_latest + , subq_3.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'listing'] SELECT - listing_id AS listing - , 1 AS bookings + 1 AS bookings + , listing_id AS listing FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_7 +) subq_3 LEFT OUTER JOIN ( - -- Read Elements From Semantic Model 'listings_latest' + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['country_latest', 'listing'] SELECT - listing_id AS listing - , country AS country_latest + country AS country_latest + , listing_id AS listing FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_9 +) subq_4 ON - subq_7.listing = subq_9.listing + subq_3.listing = subq_4.listing LEFT OUTER JOIN ( - -- Read Elements From Semantic Model 'listings_latest' + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['country_latest', 'listing'] SELECT - listing_id AS listing - , country AS country_latest + country AS country_latest + , listing_id AS listing FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_11 +) subq_5 ON - subq_7.listing = subq_11.listing + subq_3.listing = subq_5.listing diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_order_by_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_order_by_node__plan0.sql index 49a2ea3b75..4b476a6218 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_order_by_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_order_by_node__plan0.sql @@ -1,123 +1,32 @@ -- Order By ['ds__day', 'bookings'] SELECT - subq_3.ds__day - , subq_3.is_instant - , subq_3.bookings + subq_2.ds__day + , subq_2.is_instant + , subq_2.bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_2.ds__day - , subq_2.is_instant - , subq_2.bookings + subq_1.ds__day + , subq_1.is_instant + , subq_1.bookings FROM ( -- Aggregate Measures SELECT - subq_1.ds__day - , subq_1.is_instant - , SUM(subq_1.bookings) AS bookings + subq_0.ds__day + , subq_0.is_instant + , SUM(subq_0.bookings) AS bookings FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'is_instant', 'ds__day'] SELECT - subq_0.ds__day - , subq_0.is_instant - , subq_0.bookings - 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 - ) subq_1 + 1 AS bookings + , bookings_source_src_28000.is_instant + , DATE_TRUNC('day', bookings_source_src_28000.ds) AS ds__day + FROM ***************************.fct_bookings bookings_source_src_28000 + ) subq_0 GROUP BY - subq_1.ds__day - , subq_1.is_instant - ) subq_2 -) subq_3 -ORDER BY subq_3.ds__day, subq_3.bookings DESC + subq_0.ds__day + , subq_0.is_instant + ) subq_1 +) subq_2 +ORDER BY subq_2.ds__day, subq_2.bookings DESC diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_order_by_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_order_by_node__plan0_optimized.sql index bcebfe9d5f..c9f9b0f9e7 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_order_by_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_order_by_node__plan0_optimized.sql @@ -6,14 +6,14 @@ SELECT , is_instant , SUM(bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'is_instant', 'ds__day'] SELECT - DATE_TRUNC('day', ds) AS ds__day + 1 AS bookings , is_instant - , 1 AS bookings + , DATE_TRUNC('day', ds) AS ds__day FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_5 +) subq_3 GROUP BY ds__day , is_instant diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_single_join_node__plan0.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_single_join_node__plan0.sql index 1d89d14791..585245cbf1 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_single_join_node__plan0.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_single_join_node__plan0.sql @@ -1,172 +1,22 @@ -- Join Standard Outputs SELECT - subq_1.listing AS listing - , subq_1.bookings AS bookings + subq_0.listing AS listing + , subq_0.bookings AS bookings FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'listing'] SELECT - subq_0.listing - , subq_0.bookings - 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 -) subq_1 + 1 AS bookings + , bookings_source_src_28000.listing_id AS listing + FROM ***************************.fct_bookings bookings_source_src_28000 +) subq_0 LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['listing__country_latest', 'listing'] SELECT - subq_2.listing - , subq_2.listing__country_latest - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_2 -) subq_3 + listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.listing_id AS listing + FROM ***************************.dim_listings_latest listings_latest_src_28000 +) subq_1 ON - subq_1.listing = subq_3.listing + subq_0.listing = subq_1.listing diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_single_join_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_single_join_node__plan0_optimized.sql index a1cd7ac335..82a6c162a1 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_single_join_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/DuckDB/test_single_join_node__plan0_optimized.sql @@ -1,16 +1,16 @@ -- Join Standard Outputs SELECT - subq_5.listing AS listing - , subq_5.bookings AS bookings + subq_2.listing AS listing + , subq_2.bookings AS bookings FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['bookings', 'listing'] SELECT - listing_id AS listing - , 1 AS bookings + 1 AS bookings + , listing_id AS listing FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_5 +) subq_2 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_5.listing = listings_latest_src_28000.listing_id + subq_2.listing = listings_latest_src_28000.listing_id diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_combine_output_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_combine_output_node__plan0.xml index f3b4638753..dd0527cc68 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_combine_output_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_combine_output_node__plan0.xml @@ -26,7 +26,7 @@ - + @@ -40,416 +40,38 @@ - + - + - + + - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + @@ -461,405 +83,30 @@ - + - + + + - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node__plan0.xml index e806714fe9..ee5795bcea 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node__plan0.xml @@ -2,777 +2,97 @@ - - - - + + + + - - - - - - + + + + + + - - - - - - + + + + + + - + - + - + - + - + + + - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + + + - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml index ec6159a6cb..c0ce945202 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_multiple_semantic_models__plan0.xml @@ -2,9 +2,9 @@ - + - + @@ -36,7 +36,7 @@ - + @@ -55,13 +55,13 @@ - + - + - + @@ -69,10 +69,10 @@ - + - + @@ -82,1684 +82,816 @@ - + - + - + + + - - - - - - - - - + + + + + + + + + + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - + - - - - - - + - - + + - - - - - - - - + - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -1768,13 +900,13 @@ - + - + - + @@ -1782,10 +914,10 @@ - + - + @@ -1795,1299 +927,621 @@ - + - + - + + + - - - - - - - - - + + + + + + + + + + + - - + + + - + - + - - - - - - + - - - - - - - - + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.xml index 32566bd296..c95642f013 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_ratio_from_single_semantic_model__plan0.xml @@ -2,9 +2,9 @@ - + - + @@ -13,12 +13,12 @@ - - - - - - + + + + + + @@ -30,757 +30,78 @@ - - - - - - + + + + + + - - - - - - - - + + + + + + + + - + - + + + - - - - - + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + + + - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_simple_expr__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_simple_expr__plan0.xml index 461a04a81e..1a40a3d334 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_simple_expr__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_compute_metrics_node_simple_expr__plan0.xml @@ -2,9 +2,9 @@ - - - + + + @@ -16,768 +16,88 @@ - - - - - - + + + + + + - - - - - - + + + + + + - + - + - + - + - + + + - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + + + - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_constrain_time_range_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_constrain_time_range_node__plan0.xml index 6176cc9469..af689e25f9 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_constrain_time_range_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_constrain_time_range_node__plan0.xml @@ -2,416 +2,37 @@ - - - + + + - + - - + + - + + - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimension_with_joined_where_constraint__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimension_with_joined_where_constraint__plan0.xml index 0c6fb172f0..619b59db4e 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimension_with_joined_where_constraint__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimension_with_joined_where_constraint__plan0.xml @@ -1,806 +1,431 @@ - + - - - - - - + + + + + + - - - - - - - + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml index 9db49ce437..97b2aa57f5 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml @@ -1,552 +1,188 @@ - + + - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_filter_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_filter_node__plan0.xml index 7454c656d7..5a892e1460 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_filter_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_filter_node__plan0.xml @@ -1,275 +1,15 @@ - + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_filter_with_where_constraint_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_filter_with_where_constraint_node__plan0.xml index cf5619eec8..ee13e5ec85 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_filter_with_where_constraint_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_filter_with_where_constraint_node__plan0.xml @@ -2,348 +2,25 @@ - - + + - + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml index 8928db3f68..3db411db08 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_to_grain__plan0.xml @@ -2,14 +2,14 @@ - - - + + + - + @@ -19,7 +19,7 @@ - + @@ -33,8 +33,8 @@ - - + + @@ -46,948 +46,465 @@ - - - + + + - - + + - + - + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml index 8928db3f68..3db411db08 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_with_offset_window__plan0.xml @@ -2,14 +2,14 @@ - - - + + + - + @@ -19,7 +19,7 @@ - + @@ -33,8 +33,8 @@ - - + + @@ -46,948 +46,465 @@ - - - + + + - - + + - + - + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_without_offset__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_without_offset__plan0.xml index 8928db3f68..3db411db08 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_without_offset__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_join_to_time_spine_node_without_offset__plan0.xml @@ -2,14 +2,14 @@ - - - + + + - + @@ -19,7 +19,7 @@ - + @@ -33,8 +33,8 @@ - - + + @@ -46,948 +46,465 @@ - - - + + + - - + + - + - + + + - + - - - - - + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_measure_aggregation_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_measure_aggregation_node__plan0.xml index 6755985f55..3a1fa54f61 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_measure_aggregation_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_measure_aggregation_node__plan0.xml @@ -26,347 +26,30 @@ - - + + + - - - - - - - + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_multi_join_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_multi_join_node__plan0.xml index 3b55dea3fe..7a5baa49a9 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_multi_join_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_multi_join_node__plan0.xml @@ -2,794 +2,75 @@ - - - - - - + + + + + + - + - + - + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + + - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + + - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_order_by_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_order_by_node__plan0.xml index 04959b7430..766c96d133 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_order_by_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_order_by_node__plan0.xml @@ -2,28 +2,28 @@ - - - + + + - - + + - - - + + + - - + + @@ -31,450 +31,32 @@ - + - + - + + + - - - - - - + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_single_join_node__plan0.xml b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_single_join_node__plan0.xml index 6fd9ff0320..916943d3b5 100644 --- a/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_single_join_node__plan0.xml +++ b/tests_metricflow/snapshots/test_dataflow_to_sql_plan.py/SqlQueryPlan/test_single_join_node__plan0.xml @@ -2,573 +2,52 @@ - - + + - + - + + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + - + + + - - - - - - - + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + 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 bdc24e7203..82a71d7f11 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 @@ -1,451 +1,350 @@ -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_10.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_9.metric_time__day + , subq_9.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_8.metric_time__day + , COUNT(DISTINCT subq_8.bookers) AS bookers FROM ( -- Constrain Time Range to [2019-12-19T00:00:00, 2020-01-02T00:00:00] SELECT - subq_8.metric_time__day - , subq_8.bookers + subq_7.metric_time__day + , subq_7.bookers FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.bookers + subq_5.metric_time__day AS metric_time__day + , subq_4.bookers AS bookers FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_5.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_5.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy - , subq_4.ds__day AS ds__day - , subq_4.ds__week AS ds__week - , subq_4.ds__month AS ds__month - , subq_4.ds__quarter AS ds__quarter - , subq_4.ds__year AS ds__year - , subq_4.ds__extract_year AS ds__extract_year - , subq_4.ds__extract_quarter AS ds__extract_quarter - , subq_4.ds__extract_month AS ds__extract_month - , subq_4.ds__extract_day AS ds__extract_day - , subq_4.ds__extract_dow AS ds__extract_dow - , subq_4.ds__extract_doy AS ds__extract_doy - , subq_4.ds_partitioned__day AS ds_partitioned__day - , subq_4.ds_partitioned__week AS ds_partitioned__week - , subq_4.ds_partitioned__month AS ds_partitioned__month - , subq_4.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_4.ds_partitioned__year AS ds_partitioned__year - , subq_4.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_4.paid_at__day AS paid_at__day - , subq_4.paid_at__week AS paid_at__week - , subq_4.paid_at__month AS paid_at__month - , subq_4.paid_at__quarter AS paid_at__quarter - , subq_4.paid_at__year AS paid_at__year - , subq_4.paid_at__extract_year AS paid_at__extract_year - , subq_4.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_4.paid_at__extract_month AS paid_at__extract_month - , subq_4.paid_at__extract_day AS paid_at__extract_day - , subq_4.paid_at__extract_dow AS paid_at__extract_dow - , subq_4.paid_at__extract_doy AS paid_at__extract_doy - , subq_4.booking__ds__day AS booking__ds__day - , subq_4.booking__ds__week AS booking__ds__week - , subq_4.booking__ds__month AS booking__ds__month - , subq_4.booking__ds__quarter AS booking__ds__quarter - , subq_4.booking__ds__year AS booking__ds__year - , subq_4.booking__ds__extract_year AS booking__ds__extract_year - , subq_4.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_4.booking__ds__extract_month AS booking__ds__extract_month - , subq_4.booking__ds__extract_day AS booking__ds__extract_day - , subq_4.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_4.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day AS booking__paid_at__day - , subq_4.booking__paid_at__week AS booking__paid_at__week - , subq_4.booking__paid_at__month AS booking__paid_at__month - , subq_4.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_4.booking__paid_at__year AS booking__paid_at__year - , subq_4.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_4.listing AS listing - , subq_4.guest AS guest - , subq_4.host AS host - , subq_4.booking__listing AS booking__listing - , subq_4.booking__guest AS booking__guest - , subq_4.booking__host AS booking__host - , subq_4.is_instant AS is_instant - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings - , subq_4.instant_bookings AS instant_bookings - , subq_4.booking_value AS booking_value - , subq_4.max_booking_value AS max_booking_value - , subq_4.min_booking_value AS min_booking_value - , subq_4.bookers AS bookers - , subq_4.average_booking_value AS average_booking_value - , subq_4.referred_bookings AS referred_bookings - , subq_4.median_booking_value AS median_booking_value - , subq_4.booking_value_p99 AS booking_value_p99 - , subq_4.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 + subq_6.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_6 + WHERE subq_6.ds BETWEEN '2019-12-19' AND '2020-01-02' + ) subq_5 + INNER JOIN ( + -- Join Self Over Time Range + SELECT + subq_2.metric_time__day AS metric_time__day + , subq_1.ds__day AS ds__day + , subq_1.ds__week AS ds__week + , subq_1.ds__month AS ds__month + , subq_1.ds__quarter AS ds__quarter + , subq_1.ds__year AS ds__year + , subq_1.ds__extract_year AS ds__extract_year + , subq_1.ds__extract_quarter AS ds__extract_quarter + , subq_1.ds__extract_month AS ds__extract_month + , subq_1.ds__extract_day AS ds__extract_day + , subq_1.ds__extract_dow AS ds__extract_dow + , subq_1.ds__extract_doy AS ds__extract_doy + , subq_1.ds_partitioned__day AS ds_partitioned__day + , subq_1.ds_partitioned__week AS ds_partitioned__week + , subq_1.ds_partitioned__month AS ds_partitioned__month + , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_1.ds_partitioned__year AS ds_partitioned__year + , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_1.paid_at__day AS paid_at__day + , subq_1.paid_at__week AS paid_at__week + , subq_1.paid_at__month AS paid_at__month + , subq_1.paid_at__quarter AS paid_at__quarter + , subq_1.paid_at__year AS paid_at__year + , subq_1.paid_at__extract_year AS paid_at__extract_year + , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_1.paid_at__extract_month AS paid_at__extract_month + , subq_1.paid_at__extract_day AS paid_at__extract_day + , subq_1.paid_at__extract_dow AS paid_at__extract_dow + , subq_1.paid_at__extract_doy AS paid_at__extract_doy + , subq_1.booking__ds__day AS booking__ds__day + , subq_1.booking__ds__week AS booking__ds__week + , subq_1.booking__ds__month AS booking__ds__month + , subq_1.booking__ds__quarter AS booking__ds__quarter + , subq_1.booking__ds__year AS booking__ds__year + , subq_1.booking__ds__extract_year AS booking__ds__extract_year + , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_1.booking__ds__extract_month AS booking__ds__extract_month + , subq_1.booking__ds__extract_day AS booking__ds__extract_day + , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_1.booking__paid_at__day AS booking__paid_at__day + , subq_1.booking__paid_at__week AS booking__paid_at__week + , subq_1.booking__paid_at__month AS booking__paid_at__month + , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_1.booking__paid_at__year AS booking__paid_at__year + , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_1.metric_time__week AS metric_time__week + , subq_1.metric_time__month AS metric_time__month + , subq_1.metric_time__quarter AS metric_time__quarter + , subq_1.metric_time__year AS metric_time__year + , 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_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_1.listing AS listing + , subq_1.guest AS guest + , subq_1.host AS host + , subq_1.booking__listing AS booking__listing + , subq_1.booking__guest AS booking__guest + , subq_1.booking__host AS booking__host + , subq_1.is_instant AS is_instant + , subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings + , subq_1.instant_bookings AS instant_bookings + , subq_1.booking_value AS booking_value + , subq_1.max_booking_value AS max_booking_value + , subq_1.min_booking_value AS min_booking_value + , subq_1.bookers AS bookers + , subq_1.average_booking_value AS average_booking_value + , subq_1.referred_bookings AS referred_bookings + , subq_1.median_booking_value AS median_booking_value + , subq_1.booking_value_p99 AS booking_value_p99 + , 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 FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - WHERE subq_6.ds BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_5 + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 INNER JOIN ( - -- Join Self Over Time Range + -- Metric Time Dimension 'ds' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day - ) - ) subq_4 + 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 + ) subq_1 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day - ) subq_7 - ) subq_8 - WHERE subq_8.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_9 + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day + ) + ) 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 GROUP BY - subq_9.metric_time__day - ) subq_10 -) subq_11 + subq_8.metric_time__day + ) subq_9 +) subq_10 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 7f6df5eeba..647b763326 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 @@ -9,33 +9,33 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_17.metric_time__day AS metric_time__day - , COUNT(DISTINCT subq_16.bookers) AS every_2_days_bookers_2_days_ago + subq_16.metric_time__day AS metric_time__day + , COUNT(DISTINCT subq_15.bookers) AS every_2_days_bookers_2_days_ago FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_18 + FROM ***************************.mf_time_spine subq_17 WHERE ds BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_17 + ) subq_16 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_15.ds AS metric_time__day + subq_14.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_14 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_14.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_14.ds - INTERVAL 2 day ) - ) subq_16 + ) subq_15 ON - subq_17.metric_time__day - INTERVAL 2 day = subq_16.metric_time__day - WHERE subq_17.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' + subq_16.metric_time__day - INTERVAL 2 day = subq_15.metric_time__day + WHERE subq_16.metric_time__day BETWEEN '2019-12-19' AND '2020-01-02' GROUP BY - subq_17.metric_time__day -) subq_23 + subq_16.metric_time__day +) subq_21 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql index 05e4c4584c..06104f8532 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0.sql @@ -1,445 +1,243 @@ -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day + subq_8.metric_time__day , (bookings - ref_bookings) * 1.0 / bookings AS non_referred_bookings_pct FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day - , MAX(subq_4.ref_bookings) AS ref_bookings - , MAX(subq_9.bookings) AS bookings + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) AS metric_time__day + , MAX(subq_3.ref_bookings) AS ref_bookings + , MAX(subq_7.bookings) AS bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.referred_bookings AS ref_bookings + subq_2.metric_time__day + , subq_2.referred_bookings AS ref_bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.referred_bookings) AS referred_bookings + subq_1.metric_time__day + , SUM(subq_1.referred_bookings) AS referred_bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['referred_bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.referred_bookings + subq_0.ds__day AS metric_time__day + , subq_0.referred_bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 - ) subq_4 + subq_1.metric_time__day + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.bookings) AS bookings + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_4.ds__day AS metric_time__day + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ) subq_7 + 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_4 + ) subq_5 GROUP BY - subq_7.metric_time__day - ) subq_8 - ) subq_9 + subq_5.metric_time__day + ) subq_6 + ) subq_7 ON - subq_4.metric_time__day = subq_9.metric_time__day + subq_3.metric_time__day = subq_7.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) -) subq_10 + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) +) subq_8 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql index 7a90d32ec7..2004cf4a08 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric__plan0_optimized.sql @@ -18,7 +18,7 @@ FROM ( , 1 AS bookings , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_10 GROUP BY metric_time__day -) subq_15 +) subq_12 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 c4b1623e2c..efc41c18cc 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 @@ -1,104 +1,80 @@ -- Compute Metrics via Expressions SELECT - subq_7.metric_time__month + subq_6.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_5.metric_time__month + , subq_5.bookings_monthly AS bookings_last_month FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__month - , SUM(subq_5.bookings_monthly) AS bookings_monthly + subq_4.metric_time__month + , SUM(subq_4.bookings_monthly) AS bookings_monthly FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings_monthly', 'metric_time__month'] SELECT - subq_4.metric_time__month - , subq_4.bookings_monthly + subq_2.metric_time__month AS metric_time__month + , subq_1.bookings_monthly AS bookings_monthly FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__month AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__month) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__month) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__month) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__month) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__month) AS metric_time__extract_month - , subq_1.monthly_ds__month AS monthly_ds__month - , subq_1.monthly_ds__quarter AS monthly_ds__quarter - , subq_1.monthly_ds__year AS monthly_ds__year - , subq_1.monthly_ds__extract_year AS monthly_ds__extract_year - , subq_1.monthly_ds__extract_quarter AS monthly_ds__extract_quarter - , subq_1.monthly_ds__extract_month AS monthly_ds__extract_month - , subq_1.booking__monthly_ds__month AS booking__monthly_ds__month - , subq_1.booking__monthly_ds__quarter AS booking__monthly_ds__quarter - , subq_1.booking__monthly_ds__year AS booking__monthly_ds__year - , subq_1.booking__monthly_ds__extract_year AS booking__monthly_ds__extract_year - , subq_1.booking__monthly_ds__extract_quarter AS booking__monthly_ds__extract_quarter - , subq_1.booking__monthly_ds__extract_month AS booking__monthly_ds__extract_month - , subq_1.listing AS listing - , subq_1.booking__listing AS booking__listing - , subq_1.bookings_monthly AS bookings_monthly + DATE_TRUNC('month', subq_3.ds) AS metric_time__month + FROM ***************************.mf_time_spine subq_3 + GROUP BY + DATE_TRUNC('month', subq_3.ds) + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'monthly_ds' + SELECT + subq_0.monthly_ds__month + , subq_0.monthly_ds__quarter + , subq_0.monthly_ds__year + , subq_0.monthly_ds__extract_year + , subq_0.monthly_ds__extract_quarter + , subq_0.monthly_ds__extract_month + , subq_0.booking__monthly_ds__month + , subq_0.booking__monthly_ds__quarter + , subq_0.booking__monthly_ds__year + , subq_0.booking__monthly_ds__extract_year + , subq_0.booking__monthly_ds__extract_quarter + , subq_0.booking__monthly_ds__extract_month + , subq_0.monthly_ds__month AS metric_time__month + , subq_0.monthly_ds__quarter AS metric_time__quarter + , subq_0.monthly_ds__year AS metric_time__year + , subq_0.monthly_ds__extract_year AS metric_time__extract_year + , subq_0.monthly_ds__extract_quarter AS metric_time__extract_quarter + , subq_0.monthly_ds__extract_month AS metric_time__extract_month + , subq_0.listing + , subq_0.booking__listing + , subq_0.bookings_monthly FROM ( - -- Time Spine - SELECT - DATE_TRUNC('month', subq_3.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_3 - GROUP BY - DATE_TRUNC('month', subq_3.ds) - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'monthly_ds' + -- Read Elements From Semantic Model 'bookings_monthly_source' SELECT - subq_0.monthly_ds__month - , subq_0.monthly_ds__quarter - , subq_0.monthly_ds__year - , subq_0.monthly_ds__extract_year - , subq_0.monthly_ds__extract_quarter - , subq_0.monthly_ds__extract_month - , subq_0.booking__monthly_ds__month - , subq_0.booking__monthly_ds__quarter - , subq_0.booking__monthly_ds__year - , subq_0.booking__monthly_ds__extract_year - , subq_0.booking__monthly_ds__extract_quarter - , subq_0.booking__monthly_ds__extract_month - , subq_0.monthly_ds__month AS metric_time__month - , subq_0.monthly_ds__quarter AS metric_time__quarter - , subq_0.monthly_ds__year AS metric_time__year - , subq_0.monthly_ds__extract_year AS metric_time__extract_year - , subq_0.monthly_ds__extract_quarter AS metric_time__extract_quarter - , subq_0.monthly_ds__extract_month AS metric_time__extract_month - , subq_0.listing - , subq_0.booking__listing - , subq_0.bookings_monthly - FROM ( - -- Read Elements From Semantic Model 'bookings_monthly_source' - SELECT - bookings_monthly_source_src_16000.bookings_monthly - , DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) AS monthly_ds__month - , DATE_TRUNC('quarter', bookings_monthly_source_src_16000.ds) AS monthly_ds__quarter - , DATE_TRUNC('year', bookings_monthly_source_src_16000.ds) AS monthly_ds__year - , EXTRACT(year FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_year - , EXTRACT(quarter FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_quarter - , EXTRACT(month FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_month - , DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__month - , DATE_TRUNC('quarter', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__quarter - , DATE_TRUNC('year', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__year - , EXTRACT(year FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_year - , EXTRACT(quarter FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_quarter - , EXTRACT(month FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_month - , bookings_monthly_source_src_16000.listing_id AS listing - , bookings_monthly_source_src_16000.listing_id AS booking__listing - FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_16000 - ) subq_0 - ) subq_1 - ON - subq_2.metric_time__month - INTERVAL 1 month = subq_1.metric_time__month - ) subq_4 - ) subq_5 + bookings_monthly_source_src_16000.bookings_monthly + , DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) AS monthly_ds__month + , DATE_TRUNC('quarter', bookings_monthly_source_src_16000.ds) AS monthly_ds__quarter + , DATE_TRUNC('year', bookings_monthly_source_src_16000.ds) AS monthly_ds__year + , EXTRACT(year FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_year + , EXTRACT(quarter FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_quarter + , EXTRACT(month FROM bookings_monthly_source_src_16000.ds) AS monthly_ds__extract_month + , DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__month + , DATE_TRUNC('quarter', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__quarter + , DATE_TRUNC('year', bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__year + , EXTRACT(year FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_year + , EXTRACT(quarter FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_quarter + , EXTRACT(month FROM bookings_monthly_source_src_16000.ds) AS booking__monthly_ds__extract_month + , bookings_monthly_source_src_16000.listing_id AS listing + , bookings_monthly_source_src_16000.listing_id AS booking__listing + FROM ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_16000 + ) subq_0 + ) subq_1 + ON + subq_2.metric_time__month - INTERVAL 1 month = subq_1.metric_time__month + ) subq_4 GROUP BY - subq_5.metric_time__month - ) subq_6 -) subq_7 + subq_4.metric_time__month + ) subq_5 +) subq_6 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 9e93cbb724..a4a3d961c6 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 @@ -8,20 +8,20 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.metric_time__month AS metric_time__month + subq_9.metric_time__month AS metric_time__month , SUM(bookings_monthly_source_src_16000.bookings_monthly) AS bookings_last_month FROM ( -- Time Spine SELECT DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_11 + FROM ***************************.mf_time_spine subq_10 GROUP BY DATE_TRUNC('month', ds) - ) subq_10 + ) subq_9 INNER JOIN ***************************.fct_bookings_extended_monthly bookings_monthly_source_src_16000 ON - subq_10.metric_time__month - INTERVAL 1 month = DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) + subq_9.metric_time__month - INTERVAL 1 month = DATE_TRUNC('month', bookings_monthly_source_src_16000.ds) GROUP BY - subq_10.metric_time__month -) subq_15 + subq_9.metric_time__month +) subq_13 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 a9d3e6d977..0e2dc64543 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 @@ -1,129 +1,250 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_11.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 - , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_3.metric_time__day, subq_10.metric_time__day) AS metric_time__day + , MAX(subq_3.bookings) AS bookings + , MAX(subq_10.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_2.metric_time__day + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings 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 + ) subq_1 + GROUP BY + subq_1.metric_time__day + ) subq_2 + ) subq_3 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.metric_time__day + , subq_9.bookings AS bookings_at_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_8.metric_time__day + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_6.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Time Spine + SELECT + subq_7.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 + INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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.ds__day AS metric_time__day + , subq_4.ds__week AS metric_time__week + , subq_4.ds__month AS metric_time__month + , subq_4.ds__quarter AS metric_time__quarter + , subq_4.ds__year AS metric_time__year + , subq_4.ds__extract_year AS metric_time__extract_year + , subq_4.ds__extract_quarter AS metric_time__extract_quarter + , subq_4.ds__extract_month AS metric_time__extract_month + , subq_4.ds__extract_day AS metric_time__extract_day + , subq_4.ds__extract_dow AS metric_time__extract_dow + , subq_4.ds__extract_doy AS 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 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -216,340 +337,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_0 - ) subq_1 - ) subq_2 - GROUP BY - subq_2.metric_time__day - ) subq_3 - ) subq_4 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_11.metric_time__day - , subq_11.bookings AS bookings_at_start_of_month - FROM ( - -- Aggregate Measures - SELECT - subq_10.metric_time__day - , SUM(subq_10.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day'] - SELECT - subq_9.metric_time__day - , subq_9.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_7.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy - , subq_6.ds__day AS ds__day - , subq_6.ds__week AS ds__week - , subq_6.ds__month AS ds__month - , subq_6.ds__quarter AS ds__quarter - , subq_6.ds__year AS ds__year - , subq_6.ds__extract_year AS ds__extract_year - , subq_6.ds__extract_quarter AS ds__extract_quarter - , subq_6.ds__extract_month AS ds__extract_month - , subq_6.ds__extract_day AS ds__extract_day - , subq_6.ds__extract_dow AS ds__extract_dow - , subq_6.ds__extract_doy AS ds__extract_doy - , subq_6.ds_partitioned__day AS ds_partitioned__day - , subq_6.ds_partitioned__week AS ds_partitioned__week - , subq_6.ds_partitioned__month AS ds_partitioned__month - , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_6.ds_partitioned__year AS ds_partitioned__year - , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_6.paid_at__day AS paid_at__day - , subq_6.paid_at__week AS paid_at__week - , subq_6.paid_at__month AS paid_at__month - , subq_6.paid_at__quarter AS paid_at__quarter - , subq_6.paid_at__year AS paid_at__year - , subq_6.paid_at__extract_year AS paid_at__extract_year - , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_6.paid_at__extract_month AS paid_at__extract_month - , subq_6.paid_at__extract_day AS paid_at__extract_day - , subq_6.paid_at__extract_dow AS paid_at__extract_dow - , subq_6.paid_at__extract_doy AS paid_at__extract_doy - , subq_6.booking__ds__day AS booking__ds__day - , subq_6.booking__ds__week AS booking__ds__week - , subq_6.booking__ds__month AS booking__ds__month - , subq_6.booking__ds__quarter AS booking__ds__quarter - , subq_6.booking__ds__year AS booking__ds__year - , subq_6.booking__ds__extract_year AS booking__ds__extract_year - , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_6.booking__ds__extract_month AS booking__ds__extract_month - , subq_6.booking__ds__extract_day AS booking__ds__extract_day - , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_6.booking__paid_at__day AS booking__paid_at__day - , subq_6.booking__paid_at__week AS booking__paid_at__week - , subq_6.booking__paid_at__month AS booking__paid_at__month - , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_6.booking__paid_at__year AS booking__paid_at__year - , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_6.listing AS listing - , subq_6.guest AS guest - , subq_6.host AS host - , subq_6.booking__listing AS booking__listing - , subq_6.booking__guest AS booking__guest - , subq_6.booking__host AS booking__host - , subq_6.is_instant AS is_instant - , subq_6.booking__is_instant AS booking__is_instant - , subq_6.bookings AS bookings - , subq_6.instant_bookings AS instant_bookings - , subq_6.booking_value AS booking_value - , subq_6.max_booking_value AS max_booking_value - , subq_6.min_booking_value AS min_booking_value - , subq_6.bookers AS bookers - , subq_6.average_booking_value AS average_booking_value - , subq_6.referred_bookings AS referred_bookings - , subq_6.median_booking_value AS median_booking_value - , subq_6.booking_value_p99 AS booking_value_p99 - , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 ( - -- Time Spine - SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ON - DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - ) subq_9 - ) subq_10 + ) subq_4 + ) subq_5 + ON + DATE_TRUNC('month', subq_6.metric_time__day) = subq_5.metric_time__day + ) subq_8 GROUP BY - subq_10.metric_time__day - ) subq_11 - ) subq_12 + subq_8.metric_time__day + ) subq_9 + ) subq_10 ON - subq_4.metric_time__day = subq_12.metric_time__day + subq_3.metric_time__day = subq_10.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) -) subq_13 + COALESCE(subq_3.metric_time__day, subq_10.metric_time__day) +) subq_11 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 aa15f38c06..a997abb119 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_15.metric_time__day, subq_22.metric_time__day) AS metric_time__day + , MAX(subq_15.bookings) AS bookings + , MAX(subq_22.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -22,19 +22,19 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_13 GROUP BY metric_time__day - ) subq_18 + ) subq_15 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS metric_time__day - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + subq_19.ds AS metric_time__day + , SUM(subq_17.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,14 +42,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_17 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day + DATE_TRUNC('month', subq_19.ds) = subq_17.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + subq_19.ds + ) subq_22 ON - subq_18.metric_time__day = subq_26.metric_time__day + subq_15.metric_time__day = subq_22.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) -) subq_27 + COALESCE(subq_15.metric_time__day, subq_22.metric_time__day) +) subq_23 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 eb72ea9213..fed5a657fb 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 @@ -1,129 +1,250 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__week + subq_11.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 - , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_3.metric_time__week, subq_10.metric_time__week) AS metric_time__week + , MAX(subq_3.bookings) AS bookings + , MAX(subq_10.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__week - , subq_3.bookings + subq_2.metric_time__week + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__week - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__week + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__week'] SELECT - subq_1.metric_time__week - , subq_1.bookings + subq_0.ds__week AS metric_time__week + , subq_0.bookings 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 + ) subq_1 + GROUP BY + subq_1.metric_time__week + ) subq_2 + ) subq_3 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.metric_time__week + , subq_9.bookings AS bookings_at_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_8.metric_time__week + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__week'] + SELECT + DATE_TRUNC('week', subq_6.metric_time__day) AS metric_time__week + , subq_5.bookings AS bookings + FROM ( + -- Time Spine + SELECT + subq_7.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 + INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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.ds__day AS metric_time__day + , subq_4.ds__week AS metric_time__week + , subq_4.ds__month AS metric_time__month + , subq_4.ds__quarter AS metric_time__quarter + , subq_4.ds__year AS metric_time__year + , subq_4.ds__extract_year AS metric_time__extract_year + , subq_4.ds__extract_quarter AS metric_time__extract_quarter + , subq_4.ds__extract_month AS metric_time__extract_month + , subq_4.ds__extract_day AS metric_time__extract_day + , subq_4.ds__extract_dow AS metric_time__extract_dow + , subq_4.ds__extract_doy AS 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 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -216,341 +337,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_0 - ) subq_1 - ) subq_2 - GROUP BY - subq_2.metric_time__week - ) subq_3 - ) subq_4 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_11.metric_time__week - , subq_11.bookings AS bookings_at_start_of_month - FROM ( - -- Aggregate Measures - SELECT - subq_10.metric_time__week - , SUM(subq_10.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__week'] - SELECT - subq_9.metric_time__week - , subq_9.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_7.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy - , subq_6.ds__day AS ds__day - , subq_6.ds__week AS ds__week - , subq_6.ds__month AS ds__month - , subq_6.ds__quarter AS ds__quarter - , subq_6.ds__year AS ds__year - , subq_6.ds__extract_year AS ds__extract_year - , subq_6.ds__extract_quarter AS ds__extract_quarter - , subq_6.ds__extract_month AS ds__extract_month - , subq_6.ds__extract_day AS ds__extract_day - , subq_6.ds__extract_dow AS ds__extract_dow - , subq_6.ds__extract_doy AS ds__extract_doy - , subq_6.ds_partitioned__day AS ds_partitioned__day - , subq_6.ds_partitioned__week AS ds_partitioned__week - , subq_6.ds_partitioned__month AS ds_partitioned__month - , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_6.ds_partitioned__year AS ds_partitioned__year - , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_6.paid_at__day AS paid_at__day - , subq_6.paid_at__week AS paid_at__week - , subq_6.paid_at__month AS paid_at__month - , subq_6.paid_at__quarter AS paid_at__quarter - , subq_6.paid_at__year AS paid_at__year - , subq_6.paid_at__extract_year AS paid_at__extract_year - , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_6.paid_at__extract_month AS paid_at__extract_month - , subq_6.paid_at__extract_day AS paid_at__extract_day - , subq_6.paid_at__extract_dow AS paid_at__extract_dow - , subq_6.paid_at__extract_doy AS paid_at__extract_doy - , subq_6.booking__ds__day AS booking__ds__day - , subq_6.booking__ds__week AS booking__ds__week - , subq_6.booking__ds__month AS booking__ds__month - , subq_6.booking__ds__quarter AS booking__ds__quarter - , subq_6.booking__ds__year AS booking__ds__year - , subq_6.booking__ds__extract_year AS booking__ds__extract_year - , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_6.booking__ds__extract_month AS booking__ds__extract_month - , subq_6.booking__ds__extract_day AS booking__ds__extract_day - , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_6.booking__paid_at__day AS booking__paid_at__day - , subq_6.booking__paid_at__week AS booking__paid_at__week - , subq_6.booking__paid_at__month AS booking__paid_at__month - , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_6.booking__paid_at__year AS booking__paid_at__year - , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_6.listing AS listing - , subq_6.guest AS guest - , subq_6.host AS host - , subq_6.booking__listing AS booking__listing - , subq_6.booking__guest AS booking__guest - , subq_6.booking__host AS booking__host - , subq_6.is_instant AS is_instant - , subq_6.booking__is_instant AS booking__is_instant - , subq_6.bookings AS bookings - , subq_6.instant_bookings AS instant_bookings - , subq_6.booking_value AS booking_value - , subq_6.max_booking_value AS max_booking_value - , subq_6.min_booking_value AS min_booking_value - , subq_6.bookers AS bookers - , subq_6.average_booking_value AS average_booking_value - , subq_6.referred_bookings AS referred_bookings - , subq_6.median_booking_value AS median_booking_value - , subq_6.booking_value_p99 AS booking_value_p99 - , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 ( - -- Time Spine - SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ON - DATE_TRUNC('month', subq_7.metric_time__day) = subq_6.metric_time__day - WHERE DATE_TRUNC('week', subq_7.metric_time__day) = subq_7.metric_time__day - ) subq_9 - ) subq_10 + ) subq_4 + ) subq_5 + ON + DATE_TRUNC('month', subq_6.metric_time__day) = subq_5.metric_time__day + WHERE DATE_TRUNC('week', subq_6.metric_time__day) = subq_6.metric_time__day + ) subq_8 GROUP BY - subq_10.metric_time__week - ) subq_11 - ) subq_12 + subq_8.metric_time__week + ) subq_9 + ) subq_10 ON - subq_4.metric_time__week = subq_12.metric_time__week + subq_3.metric_time__week = subq_10.metric_time__week GROUP BY - COALESCE(subq_4.metric_time__week, subq_12.metric_time__week) -) subq_13 + COALESCE(subq_3.metric_time__week, subq_10.metric_time__week) +) subq_11 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 808ffc27a1..6c99b4a5ef 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) AS metric_time__week - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_15.metric_time__week, subq_22.metric_time__week) AS metric_time__week + , MAX(subq_15.bookings) AS bookings + , MAX(subq_22.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -22,19 +22,19 @@ FROM ( DATE_TRUNC('week', ds) AS metric_time__week , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_13 GROUP BY metric_time__week - ) subq_18 + ) subq_15 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__week'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('week', subq_22.ds) AS metric_time__week - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('week', subq_19.ds) AS metric_time__week + , SUM(subq_17.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,15 +42,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_17 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.metric_time__day - WHERE DATE_TRUNC('week', subq_22.ds) = subq_22.ds + DATE_TRUNC('month', subq_19.ds) = subq_17.metric_time__day + WHERE DATE_TRUNC('week', subq_19.ds) = subq_19.ds GROUP BY - DATE_TRUNC('week', subq_22.ds) - ) subq_26 + DATE_TRUNC('week', subq_19.ds) + ) subq_22 ON - subq_18.metric_time__week = subq_26.metric_time__week + subq_15.metric_time__week = subq_22.metric_time__week GROUP BY - COALESCE(subq_18.metric_time__week, subq_26.metric_time__week) -) subq_27 + COALESCE(subq_15.metric_time__week, subq_22.metric_time__week) +) subq_23 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 daf3021522..9e11caab34 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 @@ -1,129 +1,250 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_11.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 - , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_3.metric_time__day, subq_10.metric_time__day) AS metric_time__day + , MAX(subq_3.bookings) AS bookings + , MAX(subq_10.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_2.metric_time__day + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings 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 + ) subq_1 + GROUP BY + subq_1.metric_time__day + ) subq_2 + ) subq_3 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.metric_time__day + , subq_9.bookings AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + SELECT + subq_8.metric_time__day + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_6.metric_time__day AS metric_time__day + , subq_5.bookings AS bookings + FROM ( + -- Time Spine + SELECT + subq_7.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 + INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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.ds__day AS metric_time__day + , subq_4.ds__week AS metric_time__week + , subq_4.ds__month AS metric_time__month + , subq_4.ds__quarter AS metric_time__quarter + , subq_4.ds__year AS metric_time__year + , subq_4.ds__extract_year AS metric_time__extract_year + , subq_4.ds__extract_quarter AS metric_time__extract_quarter + , subq_4.ds__extract_month AS metric_time__extract_month + , subq_4.ds__extract_day AS metric_time__extract_day + , subq_4.ds__extract_dow AS metric_time__extract_dow + , subq_4.ds__extract_doy AS 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 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -216,340 +337,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_0 - ) subq_1 - ) subq_2 - GROUP BY - subq_2.metric_time__day - ) subq_3 - ) subq_4 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_11.metric_time__day - , subq_11.bookings AS bookings_2_weeks_ago - FROM ( - -- Aggregate Measures - SELECT - subq_10.metric_time__day - , SUM(subq_10.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day'] - SELECT - subq_9.metric_time__day - , subq_9.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_7.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy - , subq_6.ds__day AS ds__day - , subq_6.ds__week AS ds__week - , subq_6.ds__month AS ds__month - , subq_6.ds__quarter AS ds__quarter - , subq_6.ds__year AS ds__year - , subq_6.ds__extract_year AS ds__extract_year - , subq_6.ds__extract_quarter AS ds__extract_quarter - , subq_6.ds__extract_month AS ds__extract_month - , subq_6.ds__extract_day AS ds__extract_day - , subq_6.ds__extract_dow AS ds__extract_dow - , subq_6.ds__extract_doy AS ds__extract_doy - , subq_6.ds_partitioned__day AS ds_partitioned__day - , subq_6.ds_partitioned__week AS ds_partitioned__week - , subq_6.ds_partitioned__month AS ds_partitioned__month - , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_6.ds_partitioned__year AS ds_partitioned__year - , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_6.paid_at__day AS paid_at__day - , subq_6.paid_at__week AS paid_at__week - , subq_6.paid_at__month AS paid_at__month - , subq_6.paid_at__quarter AS paid_at__quarter - , subq_6.paid_at__year AS paid_at__year - , subq_6.paid_at__extract_year AS paid_at__extract_year - , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_6.paid_at__extract_month AS paid_at__extract_month - , subq_6.paid_at__extract_day AS paid_at__extract_day - , subq_6.paid_at__extract_dow AS paid_at__extract_dow - , subq_6.paid_at__extract_doy AS paid_at__extract_doy - , subq_6.booking__ds__day AS booking__ds__day - , subq_6.booking__ds__week AS booking__ds__week - , subq_6.booking__ds__month AS booking__ds__month - , subq_6.booking__ds__quarter AS booking__ds__quarter - , subq_6.booking__ds__year AS booking__ds__year - , subq_6.booking__ds__extract_year AS booking__ds__extract_year - , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_6.booking__ds__extract_month AS booking__ds__extract_month - , subq_6.booking__ds__extract_day AS booking__ds__extract_day - , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_6.booking__paid_at__day AS booking__paid_at__day - , subq_6.booking__paid_at__week AS booking__paid_at__week - , subq_6.booking__paid_at__month AS booking__paid_at__month - , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_6.booking__paid_at__year AS booking__paid_at__year - , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_6.listing AS listing - , subq_6.guest AS guest - , subq_6.host AS host - , subq_6.booking__listing AS booking__listing - , subq_6.booking__guest AS booking__guest - , subq_6.booking__host AS booking__host - , subq_6.is_instant AS is_instant - , subq_6.booking__is_instant AS booking__is_instant - , subq_6.bookings AS bookings - , subq_6.instant_bookings AS instant_bookings - , subq_6.booking_value AS booking_value - , subq_6.max_booking_value AS max_booking_value - , subq_6.min_booking_value AS min_booking_value - , subq_6.bookers AS bookers - , subq_6.average_booking_value AS average_booking_value - , subq_6.referred_bookings AS referred_bookings - , subq_6.median_booking_value AS median_booking_value - , subq_6.booking_value_p99 AS booking_value_p99 - , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 ( - -- Time Spine - SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + ) subq_4 + ) subq_5 + ON + subq_6.metric_time__day - INTERVAL 14 day = subq_5.metric_time__day + ) subq_8 GROUP BY - subq_10.metric_time__day - ) subq_11 - ) subq_12 + subq_8.metric_time__day + ) subq_9 + ) subq_10 ON - subq_4.metric_time__day = subq_12.metric_time__day + subq_3.metric_time__day = subq_10.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) -) subq_13 + COALESCE(subq_3.metric_time__day, subq_10.metric_time__day) +) subq_11 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 2995f673a7..2b50a9a337 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_15.metric_time__day, subq_22.metric_time__day) AS metric_time__day + , MAX(subq_15.bookings) AS bookings + , MAX(subq_22.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -22,19 +22,19 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_13 GROUP BY metric_time__day - ) subq_18 + ) subq_15 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS metric_time__day - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + subq_19.ds AS metric_time__day + , SUM(subq_17.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,14 +42,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_17 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + subq_19.ds - INTERVAL 14 day = subq_17.metric_time__day GROUP BY - subq_22.ds - ) subq_26 + subq_19.ds + ) subq_22 ON - subq_18.metric_time__day = subq_26.metric_time__day + subq_15.metric_time__day = subq_22.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) -) subq_27 + COALESCE(subq_15.metric_time__day, subq_22.metric_time__day) +) subq_23 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 6f85a9e19f..f1038c0799 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 @@ -1,129 +1,250 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__quarter + subq_11.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 - , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_3.metric_time__quarter, subq_10.metric_time__quarter) AS metric_time__quarter + , MAX(subq_3.bookings) AS bookings + , MAX(subq_10.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__quarter - , subq_3.bookings + subq_2.metric_time__quarter + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__quarter - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__quarter + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__quarter'] SELECT - subq_1.metric_time__quarter - , subq_1.bookings + subq_0.ds__quarter AS metric_time__quarter + , subq_0.bookings 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 + ) subq_1 + GROUP BY + subq_1.metric_time__quarter + ) subq_2 + ) subq_3 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.metric_time__quarter + , subq_9.bookings AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + SELECT + subq_8.metric_time__quarter + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__quarter'] + SELECT + DATE_TRUNC('quarter', subq_6.metric_time__day) AS metric_time__quarter + , subq_5.bookings AS bookings + FROM ( + -- Time Spine + SELECT + subq_7.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 + INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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.ds__day AS metric_time__day + , subq_4.ds__week AS metric_time__week + , subq_4.ds__month AS metric_time__month + , subq_4.ds__quarter AS metric_time__quarter + , subq_4.ds__year AS metric_time__year + , subq_4.ds__extract_year AS metric_time__extract_year + , subq_4.ds__extract_quarter AS metric_time__extract_quarter + , subq_4.ds__extract_month AS metric_time__extract_month + , subq_4.ds__extract_day AS metric_time__extract_day + , subq_4.ds__extract_dow AS metric_time__extract_dow + , subq_4.ds__extract_doy AS 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 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -216,340 +337,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_0 - ) subq_1 - ) subq_2 - GROUP BY - subq_2.metric_time__quarter - ) subq_3 - ) subq_4 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_11.metric_time__quarter - , subq_11.bookings AS bookings_2_weeks_ago - FROM ( - -- Aggregate Measures - SELECT - subq_10.metric_time__quarter - , SUM(subq_10.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__quarter'] - SELECT - subq_9.metric_time__quarter - , subq_9.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_7.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy - , subq_6.ds__day AS ds__day - , subq_6.ds__week AS ds__week - , subq_6.ds__month AS ds__month - , subq_6.ds__quarter AS ds__quarter - , subq_6.ds__year AS ds__year - , subq_6.ds__extract_year AS ds__extract_year - , subq_6.ds__extract_quarter AS ds__extract_quarter - , subq_6.ds__extract_month AS ds__extract_month - , subq_6.ds__extract_day AS ds__extract_day - , subq_6.ds__extract_dow AS ds__extract_dow - , subq_6.ds__extract_doy AS ds__extract_doy - , subq_6.ds_partitioned__day AS ds_partitioned__day - , subq_6.ds_partitioned__week AS ds_partitioned__week - , subq_6.ds_partitioned__month AS ds_partitioned__month - , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_6.ds_partitioned__year AS ds_partitioned__year - , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_6.paid_at__day AS paid_at__day - , subq_6.paid_at__week AS paid_at__week - , subq_6.paid_at__month AS paid_at__month - , subq_6.paid_at__quarter AS paid_at__quarter - , subq_6.paid_at__year AS paid_at__year - , subq_6.paid_at__extract_year AS paid_at__extract_year - , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_6.paid_at__extract_month AS paid_at__extract_month - , subq_6.paid_at__extract_day AS paid_at__extract_day - , subq_6.paid_at__extract_dow AS paid_at__extract_dow - , subq_6.paid_at__extract_doy AS paid_at__extract_doy - , subq_6.booking__ds__day AS booking__ds__day - , subq_6.booking__ds__week AS booking__ds__week - , subq_6.booking__ds__month AS booking__ds__month - , subq_6.booking__ds__quarter AS booking__ds__quarter - , subq_6.booking__ds__year AS booking__ds__year - , subq_6.booking__ds__extract_year AS booking__ds__extract_year - , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_6.booking__ds__extract_month AS booking__ds__extract_month - , subq_6.booking__ds__extract_day AS booking__ds__extract_day - , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_6.booking__paid_at__day AS booking__paid_at__day - , subq_6.booking__paid_at__week AS booking__paid_at__week - , subq_6.booking__paid_at__month AS booking__paid_at__month - , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_6.booking__paid_at__year AS booking__paid_at__year - , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_6.listing AS listing - , subq_6.guest AS guest - , subq_6.host AS host - , subq_6.booking__listing AS booking__listing - , subq_6.booking__guest AS booking__guest - , subq_6.booking__host AS booking__host - , subq_6.is_instant AS is_instant - , subq_6.booking__is_instant AS booking__is_instant - , subq_6.bookings AS bookings - , subq_6.instant_bookings AS instant_bookings - , subq_6.booking_value AS booking_value - , subq_6.max_booking_value AS max_booking_value - , subq_6.min_booking_value AS min_booking_value - , subq_6.bookers AS bookers - , subq_6.average_booking_value AS average_booking_value - , subq_6.referred_bookings AS referred_bookings - , subq_6.median_booking_value AS median_booking_value - , subq_6.booking_value_p99 AS booking_value_p99 - , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 ( - -- Time Spine - SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + ) subq_4 + ) subq_5 + ON + subq_6.metric_time__day - INTERVAL 14 day = subq_5.metric_time__day + ) subq_8 GROUP BY - subq_10.metric_time__quarter - ) subq_11 - ) subq_12 + subq_8.metric_time__quarter + ) subq_9 + ) subq_10 ON - subq_4.metric_time__quarter = subq_12.metric_time__quarter + subq_3.metric_time__quarter = subq_10.metric_time__quarter GROUP BY - COALESCE(subq_4.metric_time__quarter, subq_12.metric_time__quarter) -) subq_13 + COALESCE(subq_3.metric_time__quarter, subq_10.metric_time__quarter) +) subq_11 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 851b05e511..a2458eff59 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) AS metric_time__quarter - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_15.metric_time__quarter, subq_22.metric_time__quarter) AS metric_time__quarter + , MAX(subq_15.bookings) AS bookings + , MAX(subq_22.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -22,19 +22,19 @@ FROM ( DATE_TRUNC('quarter', ds) AS metric_time__quarter , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_13 GROUP BY metric_time__quarter - ) subq_18 + ) subq_15 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__quarter'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('quarter', subq_22.ds) AS metric_time__quarter - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + DATE_TRUNC('quarter', subq_19.ds) AS metric_time__quarter + , SUM(subq_17.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,14 +42,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_17 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + subq_19.ds - INTERVAL 14 day = subq_17.metric_time__day GROUP BY - DATE_TRUNC('quarter', subq_22.ds) - ) subq_26 + DATE_TRUNC('quarter', subq_19.ds) + ) subq_22 ON - subq_18.metric_time__quarter = subq_26.metric_time__quarter + subq_15.metric_time__quarter = subq_22.metric_time__quarter GROUP BY - COALESCE(subq_18.metric_time__quarter, subq_26.metric_time__quarter) -) subq_27 + COALESCE(subq_15.metric_time__quarter, subq_22.metric_time__quarter) +) subq_23 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 1d66e64171..e6a6f24ba4 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 @@ -1,665 +1,463 @@ -- Compute Metrics via Expressions SELECT - subq_16.metric_time__day + subq_14.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_6.metric_time__day, subq_13.metric_time__day) AS metric_time__day + , MAX(subq_6.month_start_bookings) AS month_start_bookings + , MAX(subq_13.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_5.metric_time__day + , subq_5.bookings AS month_start_bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_2.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 + subq_4.metric_time__day + ) subq_5 + ) subq_6 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day - , subq_14.bookings AS bookings_1_month_ago + subq_12.metric_time__day + , subq_12.bookings AS bookings_1_month_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__day - , SUM(subq_13.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_12.metric_time__day - , subq_12.bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_10.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy - , 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.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 AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 + INNER JOIN ( + -- 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.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.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.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 FROM ( - -- Time Spine - SELECT - subq_11.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_11 - ) subq_10 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' 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 - 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_8 - ) subq_9 - ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day - ) subq_12 - ) subq_13 + 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_7 + ) subq_8 + ON + subq_9.metric_time__day - INTERVAL 1 month = subq_8.metric_time__day + ) subq_11 GROUP BY - subq_13.metric_time__day - ) subq_14 - ) subq_15 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_7.metric_time__day = subq_15.metric_time__day + subq_6.metric_time__day = subq_13.metric_time__day GROUP BY - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) -) subq_16 + COALESCE(subq_6.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_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 0c68fbd1a2..b2f554d629 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 @@ -5,18 +5,18 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_32.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_21.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , MAX(subq_21.month_start_bookings) AS month_start_bookings + , MAX(subq_28.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_20.ds AS metric_time__day - , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + subq_18.ds AS metric_time__day + , SUM(subq_16.bookings) AS month_start_bookings + FROM ***************************.mf_time_spine subq_18 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -24,21 +24,21 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_16 ON - DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + DATE_TRUNC('month', subq_18.ds) = subq_16.metric_time__day GROUP BY - subq_20.ds - ) subq_24 + subq_18.ds + ) subq_21 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_28.ds AS metric_time__day - , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + subq_25.ds AS metric_time__day + , SUM(subq_23.bookings) AS bookings_1_month_ago + FROM ***************************.mf_time_spine subq_25 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -46,14 +46,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_23 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + subq_25.ds - INTERVAL 1 month = subq_23.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + subq_25.ds + ) subq_28 ON - subq_24.metric_time__day = subq_32.metric_time__day + subq_21.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) -) subq_33 + COALESCE(subq_21.metric_time__day, subq_28.metric_time__day) +) subq_29 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_derived_metric_with_offset_window_and_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 7871e327c5..b408c52a59 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 @@ -1,666 +1,464 @@ -- Compute Metrics via Expressions SELECT - subq_16.metric_time__year + subq_14.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_6.metric_time__year, subq_13.metric_time__year) AS metric_time__year + , MAX(subq_6.month_start_bookings) AS month_start_bookings + , MAX(subq_13.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_5.metric_time__year + , subq_5.bookings AS month_start_bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__year - , SUM(subq_5.bookings) AS bookings + subq_4.metric_time__year + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] SELECT - subq_4.metric_time__year - , subq_4.bookings + DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , subq_1.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - WHERE DATE_TRUNC('year', subq_2.metric_time__day) = subq_2.metric_time__day - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + WHERE DATE_TRUNC('year', subq_2.metric_time__day) = subq_2.metric_time__day + ) subq_4 GROUP BY - subq_5.metric_time__year - ) subq_6 - ) subq_7 + subq_4.metric_time__year + ) subq_5 + ) subq_6 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__year - , subq_14.bookings AS bookings_1_month_ago + subq_12.metric_time__year + , subq_12.bookings AS bookings_1_month_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__year - , SUM(subq_13.bookings) AS bookings + subq_11.metric_time__year + , SUM(subq_11.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] SELECT - subq_12.metric_time__year - , subq_12.bookings + DATE_TRUNC('year', subq_9.metric_time__day) AS metric_time__year + , subq_8.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_10.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy - , 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.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 AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 + INNER JOIN ( + -- 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.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.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.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 FROM ( - -- Time Spine - SELECT - subq_11.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_11 - ) subq_10 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' 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 - 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_8 - ) subq_9 - ON - subq_10.metric_time__day - INTERVAL 1 month = subq_9.metric_time__day - ) subq_12 - ) subq_13 + 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_7 + ) subq_8 + ON + subq_9.metric_time__day - INTERVAL 1 month = subq_8.metric_time__day + ) subq_11 GROUP BY - subq_13.metric_time__year - ) subq_14 - ) subq_15 + subq_11.metric_time__year + ) subq_12 + ) subq_13 ON - subq_7.metric_time__year = subq_15.metric_time__year + subq_6.metric_time__year = subq_13.metric_time__year GROUP BY - COALESCE(subq_7.metric_time__year, subq_15.metric_time__year) -) subq_16 + COALESCE(subq_6.metric_time__year, subq_13.metric_time__year) +) subq_14 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 76ccda3ffe..3e75e7eb91 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 @@ -5,18 +5,18 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) AS metric_time__year - , MAX(subq_24.month_start_bookings) AS month_start_bookings - , MAX(subq_32.bookings_1_month_ago) AS bookings_1_month_ago + COALESCE(subq_21.metric_time__year, subq_28.metric_time__year) AS metric_time__year + , MAX(subq_21.month_start_bookings) AS month_start_bookings + , MAX(subq_28.bookings_1_month_ago) AS bookings_1_month_ago FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', subq_20.ds) AS metric_time__year - , SUM(subq_18.bookings) AS month_start_bookings - FROM ***************************.mf_time_spine subq_20 + DATE_TRUNC('year', subq_18.ds) AS metric_time__year + , SUM(subq_16.bookings) AS month_start_bookings + FROM ***************************.mf_time_spine subq_18 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -24,22 +24,22 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_16 ON - DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day - WHERE DATE_TRUNC('year', subq_20.ds) = subq_20.ds + DATE_TRUNC('month', subq_18.ds) = subq_16.metric_time__day + WHERE DATE_TRUNC('year', subq_18.ds) = subq_18.ds GROUP BY - DATE_TRUNC('year', subq_20.ds) - ) subq_24 + DATE_TRUNC('year', subq_18.ds) + ) subq_21 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__year'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - DATE_TRUNC('year', subq_28.ds) AS metric_time__year - , SUM(subq_26.bookings) AS bookings_1_month_ago - FROM ***************************.mf_time_spine subq_28 + DATE_TRUNC('year', subq_25.ds) AS metric_time__year + , SUM(subq_23.bookings) AS bookings_1_month_ago + FROM ***************************.mf_time_spine subq_25 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -47,14 +47,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_23 ON - subq_28.ds - INTERVAL 1 month = subq_26.metric_time__day + subq_25.ds - INTERVAL 1 month = subq_23.metric_time__day GROUP BY - DATE_TRUNC('year', subq_28.ds) - ) subq_32 + DATE_TRUNC('year', subq_25.ds) + ) subq_28 ON - subq_24.metric_time__year = subq_32.metric_time__year + subq_21.metric_time__year = subq_28.metric_time__year GROUP BY - COALESCE(subq_24.metric_time__year, subq_32.metric_time__year) -) subq_33 + COALESCE(subq_21.metric_time__year, subq_28.metric_time__year) +) subq_29 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 03120b4353..93d0c25749 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 @@ -1,134 +1,262 @@ -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day + subq_13.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 - , MAX(subq_5.bookings) AS bookings - , MAX(subq_14.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_4.metric_time__day, subq_12.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 FROM ( -- Compute Metrics via Expressions SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_3.metric_time__day + , subq_3.bookings FROM ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , SUM(subq_3.bookings) AS bookings + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.bookings + subq_1.metric_time__day + , subq_1.bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings 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 + ) subq_1 + WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ) subq_4 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , subq_11.bookings AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + SELECT + subq_10.metric_time__day + , SUM(subq_10.bookings) AS bookings + FROM ( + -- Constrain Output with WHERE + SELECT + subq_9.metric_time__day + , subq_9.bookings + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__day'] + SELECT + subq_7.metric_time__day AS metric_time__day + , subq_6.bookings AS bookings + FROM ( + -- Time Spine + SELECT + subq_8.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_8 + ) subq_7 + INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.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.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy + , subq_5.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 ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -221,349 +349,19 @@ 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_0 - ) subq_1 - ) subq_2 - WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' - ) subq_3 - GROUP BY - subq_3.metric_time__day - ) subq_4 - ) subq_5 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_13.metric_time__day - , subq_13.bookings AS bookings_2_weeks_ago - FROM ( - -- Aggregate Measures - SELECT - subq_12.metric_time__day - , SUM(subq_12.bookings) AS bookings - FROM ( - -- Constrain Output with WHERE - SELECT - subq_11.metric_time__day - , subq_11.bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day'] - SELECT - subq_10.metric_time__day - , subq_10.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_8.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_8.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_8.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_8.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_8.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_8.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_8.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_8.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_8.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_8.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_8.metric_time__day) AS metric_time__extract_doy - , subq_7.ds__day AS ds__day - , subq_7.ds__week AS ds__week - , subq_7.ds__month AS ds__month - , subq_7.ds__quarter AS ds__quarter - , subq_7.ds__year AS ds__year - , subq_7.ds__extract_year AS ds__extract_year - , subq_7.ds__extract_quarter AS ds__extract_quarter - , subq_7.ds__extract_month AS ds__extract_month - , subq_7.ds__extract_day AS ds__extract_day - , subq_7.ds__extract_dow AS ds__extract_dow - , subq_7.ds__extract_doy AS ds__extract_doy - , subq_7.ds_partitioned__day AS ds_partitioned__day - , subq_7.ds_partitioned__week AS ds_partitioned__week - , subq_7.ds_partitioned__month AS ds_partitioned__month - , subq_7.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_7.ds_partitioned__year AS ds_partitioned__year - , subq_7.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_7.paid_at__day AS paid_at__day - , subq_7.paid_at__week AS paid_at__week - , subq_7.paid_at__month AS paid_at__month - , subq_7.paid_at__quarter AS paid_at__quarter - , subq_7.paid_at__year AS paid_at__year - , subq_7.paid_at__extract_year AS paid_at__extract_year - , subq_7.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_7.paid_at__extract_month AS paid_at__extract_month - , subq_7.paid_at__extract_day AS paid_at__extract_day - , subq_7.paid_at__extract_dow AS paid_at__extract_dow - , subq_7.paid_at__extract_doy AS paid_at__extract_doy - , subq_7.booking__ds__day AS booking__ds__day - , subq_7.booking__ds__week AS booking__ds__week - , subq_7.booking__ds__month AS booking__ds__month - , subq_7.booking__ds__quarter AS booking__ds__quarter - , subq_7.booking__ds__year AS booking__ds__year - , subq_7.booking__ds__extract_year AS booking__ds__extract_year - , subq_7.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_7.booking__ds__extract_month AS booking__ds__extract_month - , subq_7.booking__ds__extract_day AS booking__ds__extract_day - , subq_7.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_7.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_7.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_7.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_7.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_7.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_7.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_7.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_7.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_7.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_7.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_7.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_7.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_7.booking__paid_at__day AS booking__paid_at__day - , subq_7.booking__paid_at__week AS booking__paid_at__week - , subq_7.booking__paid_at__month AS booking__paid_at__month - , subq_7.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_7.booking__paid_at__year AS booking__paid_at__year - , subq_7.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_7.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_7.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_7.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_7.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_7.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_7.listing AS listing - , subq_7.guest AS guest - , subq_7.host AS host - , subq_7.booking__listing AS booking__listing - , subq_7.booking__guest AS booking__guest - , subq_7.booking__host AS booking__host - , subq_7.is_instant AS is_instant - , subq_7.booking__is_instant AS booking__is_instant - , subq_7.bookings AS bookings - , subq_7.instant_bookings AS instant_bookings - , subq_7.booking_value AS booking_value - , subq_7.max_booking_value AS max_booking_value - , subq_7.min_booking_value AS min_booking_value - , subq_7.bookers AS bookers - , subq_7.average_booking_value AS average_booking_value - , subq_7.referred_bookings AS referred_bookings - , subq_7.median_booking_value AS median_booking_value - , subq_7.booking_value_p99 AS booking_value_p99 - , subq_7.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 ( - -- Time Spine - SELECT - subq_9.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_9 - ) subq_8 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.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.ds__day AS metric_time__day - , subq_6.ds__week AS metric_time__week - , subq_6.ds__month AS metric_time__month - , subq_6.ds__quarter AS metric_time__quarter - , subq_6.ds__year AS metric_time__year - , subq_6.ds__extract_year AS metric_time__extract_year - , subq_6.ds__extract_quarter AS metric_time__extract_quarter - , subq_6.ds__extract_month AS metric_time__extract_month - , subq_6.ds__extract_day AS metric_time__extract_day - , subq_6.ds__extract_dow AS metric_time__extract_dow - , subq_6.ds__extract_doy AS metric_time__extract_doy - , subq_6.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 ( - -- 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_6 - ) subq_7 - ON - subq_8.metric_time__day - INTERVAL 14 day = subq_7.metric_time__day - ) subq_10 - ) subq_11 + ) subq_5 + ) subq_6 + ON + subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day + ) subq_9 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' - ) subq_12 + ) subq_10 GROUP BY - subq_12.metric_time__day - ) subq_13 - ) subq_14 + subq_10.metric_time__day + ) subq_11 + ) subq_12 ON - subq_5.metric_time__day = subq_14.metric_time__day + subq_4.metric_time__day = subq_12.metric_time__day GROUP BY - COALESCE(subq_5.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_4.metric_time__day, subq_12.metric_time__day) +) subq_13 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 86908af230..cf365d4d20 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , MAX(subq_21.bookings) AS bookings - , MAX(subq_30.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , MAX(subq_18.bookings) AS bookings + , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Aggregate Measures @@ -23,11 +23,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_18 + ) subq_15 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_21 + ) subq_18 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -39,9 +39,9 @@ FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_25.ds AS metric_time__day - , subq_23.bookings AS bookings - FROM ***************************.mf_time_spine subq_25 + subq_22.ds AS metric_time__day + , subq_20.bookings AS bookings + FROM ***************************.mf_time_spine subq_22 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -49,16 +49,16 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_23 + ) subq_20 ON - subq_25.ds - INTERVAL 14 day = subq_23.metric_time__day - ) subq_27 + subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + ) subq_23 WHERE metric_time__day = '2020-01-01' or metric_time__day = '2020-01-14' GROUP BY metric_time__day - ) subq_30 + ) subq_26 ON - subq_21.metric_time__day = subq_30.metric_time__day + subq_18.metric_time__day = subq_26.metric_time__day GROUP BY - COALESCE(subq_21.metric_time__day, subq_30.metric_time__day) -) subq_31 + COALESCE(subq_18.metric_time__day, subq_26.metric_time__day) +) subq_27 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 8d51b413df..993479ef4c 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 @@ -1,443 +1,342 @@ -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day + subq_9.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_8.metric_time__day + , subq_8.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_7.metric_time__day + , COUNT(DISTINCT subq_7.bookers) AS bookers FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.bookers + subq_5.metric_time__day AS metric_time__day + , subq_4.bookers AS bookers FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_5.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_5.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_5.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_5.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_5.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_5.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_5.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_5.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_5.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_5.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_5.metric_time__day) AS metric_time__extract_doy - , subq_4.ds__day AS ds__day - , subq_4.ds__week AS ds__week - , subq_4.ds__month AS ds__month - , subq_4.ds__quarter AS ds__quarter - , subq_4.ds__year AS ds__year - , subq_4.ds__extract_year AS ds__extract_year - , subq_4.ds__extract_quarter AS ds__extract_quarter - , subq_4.ds__extract_month AS ds__extract_month - , subq_4.ds__extract_day AS ds__extract_day - , subq_4.ds__extract_dow AS ds__extract_dow - , subq_4.ds__extract_doy AS ds__extract_doy - , subq_4.ds_partitioned__day AS ds_partitioned__day - , subq_4.ds_partitioned__week AS ds_partitioned__week - , subq_4.ds_partitioned__month AS ds_partitioned__month - , subq_4.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_4.ds_partitioned__year AS ds_partitioned__year - , subq_4.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_4.paid_at__day AS paid_at__day - , subq_4.paid_at__week AS paid_at__week - , subq_4.paid_at__month AS paid_at__month - , subq_4.paid_at__quarter AS paid_at__quarter - , subq_4.paid_at__year AS paid_at__year - , subq_4.paid_at__extract_year AS paid_at__extract_year - , subq_4.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_4.paid_at__extract_month AS paid_at__extract_month - , subq_4.paid_at__extract_day AS paid_at__extract_day - , subq_4.paid_at__extract_dow AS paid_at__extract_dow - , subq_4.paid_at__extract_doy AS paid_at__extract_doy - , subq_4.booking__ds__day AS booking__ds__day - , subq_4.booking__ds__week AS booking__ds__week - , subq_4.booking__ds__month AS booking__ds__month - , subq_4.booking__ds__quarter AS booking__ds__quarter - , subq_4.booking__ds__year AS booking__ds__year - , subq_4.booking__ds__extract_year AS booking__ds__extract_year - , subq_4.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_4.booking__ds__extract_month AS booking__ds__extract_month - , subq_4.booking__ds__extract_day AS booking__ds__extract_day - , subq_4.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_4.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_4.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_4.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_4.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_4.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_4.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_4.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_4.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_4.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_4.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_4.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_4.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_4.booking__paid_at__day AS booking__paid_at__day - , subq_4.booking__paid_at__week AS booking__paid_at__week - , subq_4.booking__paid_at__month AS booking__paid_at__month - , subq_4.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_4.booking__paid_at__year AS booking__paid_at__year - , subq_4.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_4.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_4.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_4.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_4.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_4.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_4.listing AS listing - , subq_4.guest AS guest - , subq_4.host AS host - , subq_4.booking__listing AS booking__listing - , subq_4.booking__guest AS booking__guest - , subq_4.booking__host AS booking__host - , subq_4.is_instant AS is_instant - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings - , subq_4.instant_bookings AS instant_bookings - , subq_4.booking_value AS booking_value - , subq_4.max_booking_value AS max_booking_value - , subq_4.min_booking_value AS min_booking_value - , subq_4.bookers AS bookers - , subq_4.average_booking_value AS average_booking_value - , subq_4.referred_bookings AS referred_bookings - , subq_4.median_booking_value AS median_booking_value - , subq_4.booking_value_p99 AS booking_value_p99 - , subq_4.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 + subq_6.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_6 + ) subq_5 + INNER JOIN ( + -- Join Self Over Time Range + SELECT + subq_2.metric_time__day AS metric_time__day + , subq_1.ds__day AS ds__day + , subq_1.ds__week AS ds__week + , subq_1.ds__month AS ds__month + , subq_1.ds__quarter AS ds__quarter + , subq_1.ds__year AS ds__year + , subq_1.ds__extract_year AS ds__extract_year + , subq_1.ds__extract_quarter AS ds__extract_quarter + , subq_1.ds__extract_month AS ds__extract_month + , subq_1.ds__extract_day AS ds__extract_day + , subq_1.ds__extract_dow AS ds__extract_dow + , subq_1.ds__extract_doy AS ds__extract_doy + , subq_1.ds_partitioned__day AS ds_partitioned__day + , subq_1.ds_partitioned__week AS ds_partitioned__week + , subq_1.ds_partitioned__month AS ds_partitioned__month + , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter + , subq_1.ds_partitioned__year AS ds_partitioned__year + , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year + , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter + , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month + , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day + , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow + , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy + , subq_1.paid_at__day AS paid_at__day + , subq_1.paid_at__week AS paid_at__week + , subq_1.paid_at__month AS paid_at__month + , subq_1.paid_at__quarter AS paid_at__quarter + , subq_1.paid_at__year AS paid_at__year + , subq_1.paid_at__extract_year AS paid_at__extract_year + , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter + , subq_1.paid_at__extract_month AS paid_at__extract_month + , subq_1.paid_at__extract_day AS paid_at__extract_day + , subq_1.paid_at__extract_dow AS paid_at__extract_dow + , subq_1.paid_at__extract_doy AS paid_at__extract_doy + , subq_1.booking__ds__day AS booking__ds__day + , subq_1.booking__ds__week AS booking__ds__week + , subq_1.booking__ds__month AS booking__ds__month + , subq_1.booking__ds__quarter AS booking__ds__quarter + , subq_1.booking__ds__year AS booking__ds__year + , subq_1.booking__ds__extract_year AS booking__ds__extract_year + , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter + , subq_1.booking__ds__extract_month AS booking__ds__extract_month + , subq_1.booking__ds__extract_day AS booking__ds__extract_day + , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow + , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy + , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day + , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week + , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month + , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter + , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year + , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year + , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter + , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month + , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day + , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow + , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy + , subq_1.booking__paid_at__day AS booking__paid_at__day + , subq_1.booking__paid_at__week AS booking__paid_at__week + , subq_1.booking__paid_at__month AS booking__paid_at__month + , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter + , subq_1.booking__paid_at__year AS booking__paid_at__year + , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year + , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter + , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month + , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day + , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow + , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy + , subq_1.metric_time__week AS metric_time__week + , subq_1.metric_time__month AS metric_time__month + , subq_1.metric_time__quarter AS metric_time__quarter + , subq_1.metric_time__year AS metric_time__year + , 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_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_1.listing AS listing + , subq_1.guest AS guest + , subq_1.host AS host + , subq_1.booking__listing AS booking__listing + , subq_1.booking__guest AS booking__guest + , subq_1.booking__host AS booking__host + , subq_1.is_instant AS is_instant + , subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings + , subq_1.instant_bookings AS instant_bookings + , subq_1.booking_value AS booking_value + , subq_1.max_booking_value AS max_booking_value + , subq_1.min_booking_value AS min_booking_value + , subq_1.bookers AS bookers + , subq_1.average_booking_value AS average_booking_value + , subq_1.referred_bookings AS referred_bookings + , subq_1.median_booking_value AS median_booking_value + , subq_1.booking_value_p99 AS booking_value_p99 + , 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 FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 INNER JOIN ( - -- Join Self Over Time Range + -- Metric Time Dimension 'ds' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day - ) - ) subq_4 + 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 + ) subq_1 ON - subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day - ) subq_7 - ) subq_8 + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day + ) + ) subq_4 + ON + subq_5.metric_time__day - INTERVAL 2 day = subq_4.metric_time__day + ) subq_7 GROUP BY - subq_8.metric_time__day - ) subq_9 -) subq_10 + subq_7.metric_time__day + ) subq_8 +) subq_9 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 d55d82114b..0125b5c496 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 @@ -8,26 +8,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 + subq_16.ds AS metric_time__day + , COUNT(DISTINCT subq_14.bookers) AS every_2_days_bookers_2_days_ago + FROM ***************************.mf_time_spine subq_16 INNER JOIN ( -- Join Self Over Time Range SELECT - subq_14.ds AS metric_time__day + subq_13.ds AS metric_time__day , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_14 + FROM ***************************.mf_time_spine subq_13 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_13.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_13.ds - INTERVAL 2 day ) - ) subq_15 + ) subq_14 ON - subq_17.ds - INTERVAL 2 day = subq_15.metric_time__day + subq_16.ds - INTERVAL 2 day = subq_14.metric_time__day GROUP BY - subq_17.ds -) subq_21 + subq_16.ds +) subq_19 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 d04a641f27..5b49f91708 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 @@ -1,454 +1,136 @@ -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_11.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_6.booking__ds__day, subq_10.booking__ds__day) AS booking__ds__day + , MAX(subq_6.booking_value) AS booking_value + , MAX(subq_10.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_6.booking__ds__day - , subq_6.booking_value + subq_5.booking__ds__day + , subq_5.booking_value FROM ( -- Aggregate Measures SELECT - subq_5.booking__ds__day - , SUM(subq_5.booking_value) AS booking_value + subq_4.booking__ds__day + , SUM(subq_4.booking_value) AS booking_value FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['booking_value', 'booking__ds__day'] SELECT - subq_4.booking__ds__day - , subq_4.booking_value + subq_2.booking__ds__day AS booking__ds__day + , subq_1.booking_value AS booking_value FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.booking__ds__day AS booking__ds__day - , DATE_TRUNC('week', subq_2.booking__ds__day) AS booking__ds__week - , DATE_TRUNC('month', subq_2.booking__ds__day) AS booking__ds__month - , DATE_TRUNC('quarter', subq_2.booking__ds__day) AS booking__ds__quarter - , DATE_TRUNC('year', subq_2.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM subq_2.booking__ds__day) AS booking__ds__extract_year - , EXTRACT(quarter FROM subq_2.booking__ds__day) AS booking__ds__extract_quarter - , EXTRACT(month FROM subq_2.booking__ds__day) AS booking__ds__extract_month - , EXTRACT(day FROM subq_2.booking__ds__day) AS booking__ds__extract_day - , EXTRACT(isodow FROM subq_2.booking__ds__day) AS booking__ds__extract_dow - , EXTRACT(doy FROM subq_2.booking__ds__day) AS booking__ds__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.metric_time__day AS metric_time__day - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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 - FROM ( - -- Time Spine - SELECT - subq_3.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.booking__ds__day - INTERVAL 1 week = subq_1.booking__ds__day - ) subq_4 - ) subq_5 - GROUP BY - subq_5.booking__ds__day - ) subq_6 - ) subq_7 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_11.booking__ds__day - , subq_11.bookers - FROM ( - -- Aggregate Measures - SELECT - subq_10.booking__ds__day - , COUNT(DISTINCT subq_10.bookers) AS bookers - FROM ( - -- Pass Only Elements: ['bookers', 'booking__ds__day'] - SELECT - subq_9.booking__ds__day - , subq_9.bookers - FROM ( + subq_3.ds AS booking__ds__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -541,15 +223,131 @@ 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_0 + ) subq_1 + ON + subq_2.booking__ds__day - INTERVAL 1 week = subq_1.booking__ds__day + ) subq_4 + GROUP BY + subq_4.booking__ds__day + ) subq_5 + ) subq_6 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.booking__ds__day + , subq_9.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_8.booking__ds__day + , COUNT(DISTINCT subq_8.bookers) AS bookers + FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'booking__ds__day'] + SELECT + subq_7.booking__ds__day + , subq_7.bookers + 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_7 + ) subq_8 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_8.booking__ds__day + ) subq_9 + ) subq_10 ON - subq_7.booking__ds__day = subq_12.booking__ds__day + subq_6.booking__ds__day = subq_10.booking__ds__day GROUP BY - COALESCE(subq_7.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_6.booking__ds__day, subq_10.booking__ds__day) +) subq_11 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 ee97120d59..043e4f0472 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 @@ -5,25 +5,25 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_26.bookers) AS bookers + COALESCE(subq_18.booking__ds__day, subq_22.booking__ds__day) AS booking__ds__day + , MAX(subq_18.booking_value) AS booking_value + , MAX(subq_22.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 + subq_15.ds AS booking__ds__day , SUM(bookings_source_src_28000.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + subq_15.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - ) subq_21 + subq_15.ds + ) subq_18 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,9 +36,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_26 + ) subq_22 ON - subq_21.booking__ds__day = subq_26.booking__ds__day + subq_18.booking__ds__day = subq_22.booking__ds__day GROUP BY - COALESCE(subq_21.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_18.booking__ds__day, subq_22.booking__ds__day) +) subq_23 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 380c658a9e..e843eeecce 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 @@ -1,329 +1,228 @@ -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_6.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_5.metric_time__day + , subq_5.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_2.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_4 GROUP BY - subq_5.metric_time__day - ) subq_6 -) subq_7 + subq_4.metric_time__day + ) subq_5 +) subq_6 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 cfa50604ff..f668721613 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 @@ -8,9 +8,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 + subq_10.ds AS metric_time__day + , SUM(subq_8.bookings) AS bookings_5_days_ago + FROM ***************************.mf_time_spine subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -18,9 +18,9 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_8 ON - subq_11.ds - INTERVAL 5 day = subq_9.metric_time__day + subq_10.ds - INTERVAL 5 day = subq_8.metric_time__day GROUP BY - subq_11.ds -) subq_15 + subq_10.ds +) subq_13 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_multi_metric_fill_null__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_multi_metric_fill_null__plan0.sql index f4cd3a7185..20ad84cf86 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_multi_metric_fill_null__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_multi_metric_fill_null__plan0.sql @@ -1,382 +1,211 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_5.metric_time__day, subq_10.metric_time__day) AS metric_time__day - , MAX(subq_5.twice_bookings_fill_nulls_with_0_without_time_spine) AS twice_bookings_fill_nulls_with_0_without_time_spine - , MAX(subq_10.listings) AS listings + COALESCE(subq_4.metric_time__day, subq_8.metric_time__day) AS metric_time__day + , MAX(subq_4.twice_bookings_fill_nulls_with_0_without_time_spine) AS twice_bookings_fill_nulls_with_0_without_time_spine + , MAX(subq_8.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT - subq_4.metric_time__day + subq_3.metric_time__day , 2 * bookings_fill_nulls_with_0_without_time_spine AS twice_bookings_fill_nulls_with_0_without_time_spine FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine + subq_2.metric_time__day + , COALESCE(subq_2.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 - ) subq_4 -) subq_5 + subq_1.metric_time__day + ) subq_2 + ) subq_3 +) subq_4 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day - , subq_9.listings + subq_7.metric_time__day + , subq_7.listings FROM ( -- Aggregate Measures SELECT - subq_8.metric_time__day - , SUM(subq_8.listings) AS listings + subq_6.metric_time__day + , SUM(subq_6.listings) AS listings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['listings', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.listings + subq_5.ds__day AS metric_time__day + , subq_5.listings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.created_at__day - , subq_6.created_at__week - , subq_6.created_at__month - , subq_6.created_at__quarter - , subq_6.created_at__year - , subq_6.created_at__extract_year - , subq_6.created_at__extract_quarter - , subq_6.created_at__extract_month - , subq_6.created_at__extract_day - , subq_6.created_at__extract_dow - , subq_6.created_at__extract_doy - , subq_6.listing__ds__day - , subq_6.listing__ds__week - , subq_6.listing__ds__month - , subq_6.listing__ds__quarter - , subq_6.listing__ds__year - , subq_6.listing__ds__extract_year - , subq_6.listing__ds__extract_quarter - , subq_6.listing__ds__extract_month - , subq_6.listing__ds__extract_day - , subq_6.listing__ds__extract_dow - , subq_6.listing__ds__extract_doy - , subq_6.listing__created_at__day - , subq_6.listing__created_at__week - , subq_6.listing__created_at__month - , subq_6.listing__created_at__quarter - , subq_6.listing__created_at__year - , subq_6.listing__created_at__extract_year - , subq_6.listing__created_at__extract_quarter - , subq_6.listing__created_at__extract_month - , subq_6.listing__created_at__extract_day - , subq_6.listing__created_at__extract_dow - , subq_6.listing__created_at__extract_doy - , subq_6.ds__day AS metric_time__day - , subq_6.ds__week AS metric_time__week - , subq_6.ds__month AS metric_time__month - , subq_6.ds__quarter AS metric_time__quarter - , subq_6.ds__year AS metric_time__year - , subq_6.ds__extract_year AS metric_time__extract_year - , subq_6.ds__extract_quarter AS metric_time__extract_quarter - , subq_6.ds__extract_month AS metric_time__extract_month - , subq_6.ds__extract_day AS metric_time__extract_day - , subq_6.ds__extract_dow AS metric_time__extract_dow - , subq_6.ds__extract_doy AS metric_time__extract_doy - , subq_6.listing - , subq_6.user - , subq_6.listing__user - , subq_6.country_latest - , subq_6.is_lux_latest - , subq_6.capacity_latest - , subq_6.listing__country_latest - , subq_6.listing__is_lux_latest - , subq_6.listing__capacity_latest - , subq_6.listings - , subq_6.largest_listing - , subq_6.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_6 - ) subq_7 - ) subq_8 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_5 + ) subq_6 GROUP BY - subq_8.metric_time__day - ) subq_9 -) subq_10 + subq_6.metric_time__day + ) subq_7 +) subq_8 ON - subq_5.metric_time__day = subq_10.metric_time__day + subq_4.metric_time__day = subq_8.metric_time__day GROUP BY - COALESCE(subq_5.metric_time__day, subq_10.metric_time__day) + COALESCE(subq_4.metric_time__day, subq_8.metric_time__day) diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_multi_metric_fill_null__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_multi_metric_fill_null__plan0_optimized.sql index 6042d3ec26..6a4115cda1 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_multi_metric_fill_null__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_multi_metric_fill_null__plan0_optimized.sql @@ -1,8 +1,8 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_16.metric_time__day, subq_21.metric_time__day) AS metric_time__day - , MAX(subq_16.twice_bookings_fill_nulls_with_0_without_time_spine) AS twice_bookings_fill_nulls_with_0_without_time_spine - , MAX(subq_21.listings) AS listings + COALESCE(subq_13.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , MAX(subq_13.twice_bookings_fill_nulls_with_0_without_time_spine) AS twice_bookings_fill_nulls_with_0_without_time_spine + , MAX(subq_17.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT @@ -26,12 +26,12 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_10 GROUP BY metric_time__day - ) subq_14 - ) subq_15 -) subq_16 + ) subq_11 + ) subq_12 +) subq_13 FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -46,11 +46,11 @@ FULL OUTER JOIN ( DATE_TRUNC('day', created_at) AS metric_time__day , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_19 + ) subq_15 GROUP BY metric_time__day -) subq_21 +) subq_17 ON - subq_16.metric_time__day = subq_21.metric_time__day + subq_13.metric_time__day = subq_17.metric_time__day GROUP BY - COALESCE(subq_16.metric_time__day, subq_21.metric_time__day) + COALESCE(subq_13.metric_time__day, subq_17.metric_time__day) diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql index 2968237130..1034a594cf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0.sql @@ -1,895 +1,491 @@ -- Compute Metrics via Expressions SELECT - subq_22.metric_time__day + subq_18.metric_time__day , non_referred + (instant * 1.0 / bookings) AS instant_plus_non_referred_bookings_pct FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_11.metric_time__day, subq_16.metric_time__day, subq_21.metric_time__day) AS metric_time__day - , MAX(subq_11.non_referred) AS non_referred - , MAX(subq_16.instant) AS instant - , MAX(subq_21.bookings) AS bookings + COALESCE(subq_9.metric_time__day, subq_13.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , MAX(subq_9.non_referred) AS non_referred + , MAX(subq_13.instant) AS instant + , MAX(subq_17.bookings) AS bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day + subq_8.metric_time__day , (bookings - ref_bookings) * 1.0 / bookings AS non_referred FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day - , MAX(subq_4.ref_bookings) AS ref_bookings - , MAX(subq_9.bookings) AS bookings + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) AS metric_time__day + , MAX(subq_3.ref_bookings) AS ref_bookings + , MAX(subq_7.bookings) AS bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.referred_bookings AS ref_bookings + subq_2.metric_time__day + , subq_2.referred_bookings AS ref_bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.referred_bookings) AS referred_bookings + subq_1.metric_time__day + , SUM(subq_1.referred_bookings) AS referred_bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['referred_bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.referred_bookings + subq_0.ds__day AS metric_time__day + , subq_0.referred_bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 - ) subq_4 + subq_1.metric_time__day + ) subq_2 + ) subq_3 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.bookings) AS bookings + subq_5.metric_time__day + , SUM(subq_5.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_4.ds__day AS metric_time__day + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ) subq_7 + 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_4 + ) subq_5 GROUP BY - subq_7.metric_time__day - ) subq_8 - ) subq_9 + subq_5.metric_time__day + ) subq_6 + ) subq_7 ON - subq_4.metric_time__day = subq_9.metric_time__day + subq_3.metric_time__day = subq_7.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) - ) subq_10 - ) subq_11 + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) + ) subq_8 + ) subq_9 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day - , subq_15.instant_bookings AS instant + subq_12.metric_time__day + , subq_12.instant_bookings AS instant FROM ( -- Aggregate Measures SELECT - subq_14.metric_time__day - , SUM(subq_14.instant_bookings) AS instant_bookings + subq_11.metric_time__day + , SUM(subq_11.instant_bookings) AS instant_bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['instant_bookings', 'metric_time__day'] SELECT - subq_13.metric_time__day - , subq_13.instant_bookings + subq_10.ds__day AS metric_time__day + , subq_10.instant_bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 - 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_12 - ) subq_13 - ) subq_14 + 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_10 + ) subq_11 GROUP BY - subq_14.metric_time__day - ) subq_15 - ) subq_16 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_11.metric_time__day = subq_16.metric_time__day + subq_9.metric_time__day = subq_13.metric_time__day FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_20.metric_time__day - , subq_20.bookings + subq_16.metric_time__day + , subq_16.bookings FROM ( -- Aggregate Measures SELECT - subq_19.metric_time__day - , SUM(subq_19.bookings) AS bookings + subq_15.metric_time__day + , SUM(subq_15.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_18.metric_time__day - , subq_18.bookings + subq_14.ds__day AS metric_time__day + , subq_14.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_17.ds__day - , subq_17.ds__week - , subq_17.ds__month - , subq_17.ds__quarter - , subq_17.ds__year - , subq_17.ds__extract_year - , subq_17.ds__extract_quarter - , subq_17.ds__extract_month - , subq_17.ds__extract_day - , subq_17.ds__extract_dow - , subq_17.ds__extract_doy - , subq_17.ds_partitioned__day - , subq_17.ds_partitioned__week - , subq_17.ds_partitioned__month - , subq_17.ds_partitioned__quarter - , subq_17.ds_partitioned__year - , subq_17.ds_partitioned__extract_year - , subq_17.ds_partitioned__extract_quarter - , subq_17.ds_partitioned__extract_month - , subq_17.ds_partitioned__extract_day - , subq_17.ds_partitioned__extract_dow - , subq_17.ds_partitioned__extract_doy - , subq_17.paid_at__day - , subq_17.paid_at__week - , subq_17.paid_at__month - , subq_17.paid_at__quarter - , subq_17.paid_at__year - , subq_17.paid_at__extract_year - , subq_17.paid_at__extract_quarter - , subq_17.paid_at__extract_month - , subq_17.paid_at__extract_day - , subq_17.paid_at__extract_dow - , subq_17.paid_at__extract_doy - , subq_17.booking__ds__day - , subq_17.booking__ds__week - , subq_17.booking__ds__month - , subq_17.booking__ds__quarter - , subq_17.booking__ds__year - , subq_17.booking__ds__extract_year - , subq_17.booking__ds__extract_quarter - , subq_17.booking__ds__extract_month - , subq_17.booking__ds__extract_day - , subq_17.booking__ds__extract_dow - , subq_17.booking__ds__extract_doy - , subq_17.booking__ds_partitioned__day - , subq_17.booking__ds_partitioned__week - , subq_17.booking__ds_partitioned__month - , subq_17.booking__ds_partitioned__quarter - , subq_17.booking__ds_partitioned__year - , subq_17.booking__ds_partitioned__extract_year - , subq_17.booking__ds_partitioned__extract_quarter - , subq_17.booking__ds_partitioned__extract_month - , subq_17.booking__ds_partitioned__extract_day - , subq_17.booking__ds_partitioned__extract_dow - , subq_17.booking__ds_partitioned__extract_doy - , subq_17.booking__paid_at__day - , subq_17.booking__paid_at__week - , subq_17.booking__paid_at__month - , subq_17.booking__paid_at__quarter - , subq_17.booking__paid_at__year - , subq_17.booking__paid_at__extract_year - , subq_17.booking__paid_at__extract_quarter - , subq_17.booking__paid_at__extract_month - , subq_17.booking__paid_at__extract_day - , subq_17.booking__paid_at__extract_dow - , subq_17.booking__paid_at__extract_doy - , subq_17.ds__day AS metric_time__day - , subq_17.ds__week AS metric_time__week - , subq_17.ds__month AS metric_time__month - , subq_17.ds__quarter AS metric_time__quarter - , subq_17.ds__year AS metric_time__year - , subq_17.ds__extract_year AS metric_time__extract_year - , subq_17.ds__extract_quarter AS metric_time__extract_quarter - , subq_17.ds__extract_month AS metric_time__extract_month - , subq_17.ds__extract_day AS metric_time__extract_day - , subq_17.ds__extract_dow AS metric_time__extract_dow - , subq_17.ds__extract_doy AS metric_time__extract_doy - , subq_17.listing - , subq_17.guest - , subq_17.host - , subq_17.booking__listing - , subq_17.booking__guest - , subq_17.booking__host - , subq_17.is_instant - , subq_17.booking__is_instant - , subq_17.bookings - , subq_17.instant_bookings - , subq_17.booking_value - , subq_17.max_booking_value - , subq_17.min_booking_value - , subq_17.bookers - , subq_17.average_booking_value - , subq_17.referred_bookings - , subq_17.median_booking_value - , subq_17.booking_value_p99 - , subq_17.discrete_booking_value_p99 - , subq_17.approximate_continuous_booking_value_p99 - , subq_17.approximate_discrete_booking_value_p99 - 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_17 - ) subq_18 - ) subq_19 + 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_14 + ) subq_15 GROUP BY - subq_19.metric_time__day - ) subq_20 - ) subq_21 + subq_15.metric_time__day + ) subq_16 + ) subq_17 ON - COALESCE(subq_11.metric_time__day, subq_16.metric_time__day) = subq_21.metric_time__day + COALESCE(subq_9.metric_time__day, subq_13.metric_time__day) = subq_17.metric_time__day GROUP BY - COALESCE(subq_11.metric_time__day, subq_16.metric_time__day, subq_21.metric_time__day) -) subq_22 + COALESCE(subq_9.metric_time__day, subq_13.metric_time__day, subq_17.metric_time__day) +) subq_18 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql index 1498999a60..3984652acf 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_derived_metric__plan0_optimized.sql @@ -5,10 +5,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_28.metric_time__day, subq_33.metric_time__day) AS metric_time__day - , MAX(subq_28.non_referred) AS non_referred - , MAX(subq_33.instant) AS instant - , MAX(subq_33.bookings) AS bookings + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) AS metric_time__day + , MAX(subq_23.non_referred) AS non_referred + , MAX(subq_27.instant) AS instant + , MAX(subq_27.bookings) AS bookings FROM ( -- Compute Metrics via Expressions SELECT @@ -30,11 +30,11 @@ FROM ( , 1 AS bookings , CASE WHEN referrer_id IS NOT NULL THEN 1 ELSE 0 END AS referred_bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_25 + ) subq_20 GROUP BY metric_time__day - ) subq_27 - ) subq_28 + ) subq_22 + ) subq_23 FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -51,12 +51,12 @@ FROM ( , 1 AS bookings , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_31 + ) subq_25 GROUP BY metric_time__day - ) subq_33 + ) subq_27 ON - subq_28.metric_time__day = subq_33.metric_time__day + subq_23.metric_time__day = subq_27.metric_time__day GROUP BY - COALESCE(subq_28.metric_time__day, subq_33.metric_time__day) -) subq_34 + COALESCE(subq_23.metric_time__day, subq_27.metric_time__day) +) subq_28 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 aa0490fb4b..7511cda3fd 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 @@ -1,369 +1,262 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day + subq_11.metric_time__day , 2 * bookings_offset_once AS bookings_offset_twice FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['metric_time__day', 'bookings_offset_once'] SELECT - subq_12.metric_time__day - , subq_12.bookings_offset_once + subq_10.metric_time__day + , subq_10.bookings_offset_once FROM ( - -- Constrain Output with WHERE + -- Join to Time Spine Dataset SELECT - subq_11.metric_time__day - , subq_11.booking__is_instant - , subq_11.bookings_offset_once + subq_8.metric_time__day AS metric_time__day + , subq_7.booking__is_instant AS booking__is_instant + , subq_7.bookings_offset_once AS bookings_offset_once FROM ( - -- Join to Time Spine Dataset + -- Time Spine 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_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 + INNER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_6.metric_time__day + , subq_6.booking__is_instant + , 2 * bookings AS bookings_offset_once FROM ( - -- Time Spine - SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 - INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , 2 * bookings AS bookings_offset_once + subq_5.metric_time__day + , subq_5.booking__is_instant + , subq_5.bookings FROM ( - -- Compute Metrics via Expressions + -- Aggregate Measures SELECT - subq_6.metric_time__day - , subq_6.booking__is_instant - , subq_6.bookings + subq_4.metric_time__day + , subq_4.booking__is_instant + , SUM(subq_4.bookings) AS bookings FROM ( - -- Aggregate Measures + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_5.metric_time__day - , subq_5.booking__is_instant - , SUM(subq_5.bookings) AS bookings + subq_2.metric_time__day AS metric_time__day + , subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] + -- Time Spine + SELECT + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' SELECT - subq_4.metric_time__day - , subq_4.booking__is_instant - , subq_4.bookings + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Join to Time Spine Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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 - FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 - GROUP BY - subq_5.metric_time__day - , subq_5.booking__is_instant - ) subq_6 - ) subq_7 - ) subq_8 - ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 - WHERE booking__is_instant - ) subq_12 -) subq_13 + 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 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_4 + GROUP BY + subq_4.metric_time__day + , subq_4.booking__is_instant + ) subq_5 + ) subq_6 + ) subq_7 + ON + subq_8.metric_time__day - INTERVAL 2 day = subq_7.metric_time__day + ) subq_10 + WHERE booking__is_instant +) subq_11 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 94a07bed7d..b0f541139b 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 @@ -11,10 +11,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 + subq_21.ds AS metric_time__day + , subq_19.booking__is_instant AS booking__is_instant + , subq_19.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine subq_21 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -27,10 +27,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 + subq_15.ds AS metric_time__day + , subq_13.booking__is_instant AS booking__is_instant + , SUM(subq_13.bookings) AS bookings + FROM ***************************.mf_time_spine subq_15 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -39,16 +39,16 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + ) subq_13 ON - subq_17.ds - INTERVAL 5 day = subq_15.metric_time__day + subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day GROUP BY - subq_17.ds - , subq_15.booking__is_instant - ) subq_21 - ) subq_22 + subq_15.ds + , subq_13.booking__is_instant + ) subq_18 + ) subq_19 ON - subq_24.ds - INTERVAL 2 day = subq_22.metric_time__day - ) subq_25 + subq_21.ds - INTERVAL 2 day = subq_19.metric_time__day + ) subq_22 WHERE booking__is_instant -) subq_27 +) subq_23 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 5ac836a079..3b99868ed2 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 @@ -1,369 +1,45 @@ -- Compute Metrics via Expressions SELECT - subq_15.metric_time__day + subq_13.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_7.metric_time__day, subq_12.metric_time__day) AS metric_time__day + , MAX(subq_7.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_12.booking_fees) AS booking_fees FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.booking_fees_start_of_month AS booking_fees_start_of_month + subq_5.metric_time__day AS metric_time__day + , subq_4.booking_fees_start_of_month AS booking_fees_start_of_month FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_6.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_6 + ) subq_5 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_4.metric_time__day + subq_3.metric_time__day , booking_value * 0.05 AS booking_fees_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.booking_value + subq_2.metric_time__day + , subq_2.booking_value FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.booking_value) AS booking_value - FROM ( - -- Pass Only Elements: ['booking_value', 'metric_time__day'] - SELECT - subq_1.metric_time__day - , subq_1.booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - GROUP BY - subq_2.metric_time__day - ) subq_3 - ) subq_4 - ) subq_5 - ON - DATE_TRUNC('month', subq_6.metric_time__day) = subq_5.metric_time__day - ) subq_8 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_13.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 - FROM ( - -- Aggregate Measures - SELECT - subq_11.metric_time__day - , SUM(subq_11.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_1.metric_time__day + , SUM(subq_1.booking_value) AS booking_value FROM ( -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['booking_value', 'metric_time__day'] 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_0.ds__day AS metric_time__day + , subq_0.booking_value FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -456,16 +132,138 @@ 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_0 + ) subq_1 + GROUP BY + subq_1.metric_time__day + ) subq_2 + ) subq_3 + ) subq_4 + ON + DATE_TRUNC('month', subq_5.metric_time__day) = subq_4.metric_time__day + ) subq_7 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_11.metric_time__day + , booking_value * 0.05 AS booking_fees + FROM ( + -- Compute Metrics via Expressions + SELECT + subq_10.metric_time__day + , subq_10.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_9.metric_time__day + , SUM(subq_9.booking_value) AS booking_value + FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['booking_value', 'metric_time__day'] + SELECT + subq_8.ds__day AS metric_time__day + , subq_8.booking_value + 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_8 + ) subq_9 GROUP BY - subq_11.metric_time__day - ) subq_12 - ) subq_13 - ) subq_14 + subq_9.metric_time__day + ) subq_10 + ) subq_11 + ) subq_12 ON - subq_8.metric_time__day = subq_14.metric_time__day + subq_7.metric_time__day = subq_12.metric_time__day GROUP BY - COALESCE(subq_8.metric_time__day, subq_14.metric_time__day) -) subq_15 + COALESCE(subq_7.metric_time__day, subq_12.metric_time__day) +) subq_13 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 b10c0ed06c..189c4c86fb 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 @@ -5,15 +5,15 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_30.metric_time__day) AS metric_time__day - , MAX(subq_24.booking_fees_start_of_month) AS booking_fees_start_of_month - , MAX(subq_30.booking_fees) AS booking_fees + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day + , MAX(subq_21.booking_fees_start_of_month) AS booking_fees_start_of_month + , MAX(subq_26.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 + subq_20.ds AS metric_time__day + , subq_18.booking_fees_start_of_month AS booking_fees_start_of_month + FROM ***************************.mf_time_spine subq_20 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -31,11 +31,11 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_20 - ) subq_21 + ) subq_17 + ) subq_18 ON - DATE_TRUNC('month', subq_23.ds) = subq_21.metric_time__day - ) subq_24 + DATE_TRUNC('month', subq_20.ds) = subq_18.metric_time__day + ) subq_21 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT @@ -53,10 +53,10 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_29 - ) subq_30 + ) subq_25 + ) subq_26 ON - subq_24.metric_time__day = subq_30.metric_time__day + subq_21.metric_time__day = subq_26.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_30.metric_time__day) -) subq_31 + COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) +) subq_27 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine__plan0.sql index 4fe4b35f3c..86a547c934 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine__plan0.sql @@ -1,225 +1,124 @@ -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day + subq_4.metric_time__day , 3 * twice_bookings_fill_nulls_with_0_without_time_spine AS nested_fill_nulls_without_time_spine FROM ( -- Compute Metrics via Expressions SELECT - subq_4.metric_time__day + subq_3.metric_time__day , 2 * bookings_fill_nulls_with_0_without_time_spine AS twice_bookings_fill_nulls_with_0_without_time_spine FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine + subq_2.metric_time__day + , COALESCE(subq_2.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 - ) subq_4 -) subq_5 + subq_1.metric_time__day + ) subq_2 + ) subq_3 +) subq_4 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine__plan0_optimized.sql index 12c8099228..2568cd4f2d 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine__plan0_optimized.sql @@ -25,9 +25,9 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_8 + ) subq_6 GROUP BY metric_time__day - ) subq_9 - ) subq_10 -) subq_11 + ) subq_7 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine_multi_metric__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine_multi_metric__plan0.sql index 7f9b46ce11..4fd9c7be22 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine_multi_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine_multi_metric__plan0.sql @@ -1,388 +1,217 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.nested_fill_nulls_without_time_spine) AS nested_fill_nulls_without_time_spine - , MAX(subq_11.listings) AS listings + COALESCE(subq_5.metric_time__day, subq_9.metric_time__day) AS metric_time__day + , MAX(subq_5.nested_fill_nulls_without_time_spine) AS nested_fill_nulls_without_time_spine + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day + subq_4.metric_time__day , 3 * twice_bookings_fill_nulls_with_0_without_time_spine AS nested_fill_nulls_without_time_spine FROM ( -- Compute Metrics via Expressions SELECT - subq_4.metric_time__day + subq_3.metric_time__day , 2 * bookings_fill_nulls_with_0_without_time_spine AS twice_bookings_fill_nulls_with_0_without_time_spine FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine + subq_2.metric_time__day + , COALESCE(subq_2.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 - ) subq_4 - ) subq_5 -) subq_6 + subq_1.metric_time__day + ) subq_2 + ) subq_3 + ) subq_4 +) subq_5 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.listings + subq_8.metric_time__day + , subq_8.listings FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , SUM(subq_9.listings) AS listings + subq_7.metric_time__day + , SUM(subq_7.listings) AS listings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['listings', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.listings + subq_6.ds__day AS metric_time__day + , subq_6.listings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'listings_latest' 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.created_at__day - , subq_7.created_at__week - , subq_7.created_at__month - , subq_7.created_at__quarter - , subq_7.created_at__year - , subq_7.created_at__extract_year - , subq_7.created_at__extract_quarter - , subq_7.created_at__extract_month - , subq_7.created_at__extract_day - , subq_7.created_at__extract_dow - , subq_7.created_at__extract_doy - , subq_7.listing__ds__day - , subq_7.listing__ds__week - , subq_7.listing__ds__month - , subq_7.listing__ds__quarter - , subq_7.listing__ds__year - , subq_7.listing__ds__extract_year - , subq_7.listing__ds__extract_quarter - , subq_7.listing__ds__extract_month - , subq_7.listing__ds__extract_day - , subq_7.listing__ds__extract_dow - , subq_7.listing__ds__extract_doy - , subq_7.listing__created_at__day - , subq_7.listing__created_at__week - , subq_7.listing__created_at__month - , subq_7.listing__created_at__quarter - , subq_7.listing__created_at__year - , subq_7.listing__created_at__extract_year - , subq_7.listing__created_at__extract_quarter - , subq_7.listing__created_at__extract_month - , subq_7.listing__created_at__extract_day - , subq_7.listing__created_at__extract_dow - , subq_7.listing__created_at__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.listing - , subq_7.user - , subq_7.listing__user - , subq_7.country_latest - , subq_7.is_lux_latest - , subq_7.capacity_latest - , subq_7.listing__country_latest - , subq_7.listing__is_lux_latest - , subq_7.listing__capacity_latest - , subq_7.listings - , subq_7.largest_listing - , subq_7.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_7 - ) subq_8 - ) subq_9 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_6 + ) subq_7 GROUP BY - subq_9.metric_time__day - ) subq_10 -) subq_11 + subq_7.metric_time__day + ) subq_8 +) subq_9 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_5.metric_time__day = subq_9.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) + COALESCE(subq_5.metric_time__day, subq_9.metric_time__day) diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine_multi_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine_multi_metric__plan0_optimized.sql index 3fbce2627b..f5ee6d1f7e 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine_multi_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_fill_nulls_without_time_spine_multi_metric__plan0_optimized.sql @@ -1,8 +1,8 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__day, subq_23.metric_time__day) AS metric_time__day - , MAX(subq_18.nested_fill_nulls_without_time_spine) AS nested_fill_nulls_without_time_spine - , MAX(subq_23.listings) AS listings + COALESCE(subq_15.metric_time__day, subq_19.metric_time__day) AS metric_time__day + , MAX(subq_15.nested_fill_nulls_without_time_spine) AS nested_fill_nulls_without_time_spine + , MAX(subq_19.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT @@ -31,13 +31,13 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_11 GROUP BY metric_time__day - ) subq_15 - ) subq_16 - ) subq_17 -) subq_18 + ) subq_12 + ) subq_13 + ) subq_14 +) subq_15 FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -52,11 +52,11 @@ FULL OUTER JOIN ( DATE_TRUNC('day', created_at) AS metric_time__day , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_21 + ) subq_17 GROUP BY metric_time__day -) subq_23 +) subq_19 ON - subq_18.metric_time__day = subq_23.metric_time__day + subq_15.metric_time__day = subq_19.metric_time__day GROUP BY - COALESCE(subq_18.metric_time__day, subq_23.metric_time__day) + COALESCE(subq_15.metric_time__day, subq_19.metric_time__day) diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0.sql index 4569d672d5..d8284579b0 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0.sql @@ -8,991 +8,515 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_30.booking_value) AS booking_value + MAX(subq_7.average_booking_value) AS average_booking_value + , MAX(subq_15.bookings) AS bookings + , MAX(subq_20.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.average_booking_value + subq_6.average_booking_value FROM ( -- Aggregate Measures SELECT - AVG(subq_9.average_booking_value) AS average_booking_value + AVG(subq_5.average_booking_value) AS average_booking_value FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value',] SELECT - subq_8.average_booking_value + subq_4.average_booking_value FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_7.booking__is_instant - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_1.booking__is_instant AS booking__is_instant + , subq_1.average_booking_value AS average_booking_value FROM ( - -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'booking__is_instant'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] SELECT - subq_6.booking__is_instant - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_0.listing + , subq_0.booking__is_instant + , subq_0.average_booking_value FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value - FROM ( - -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'listing'] - SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.average_booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['is_lux_latest', 'listing'] - SELECT - subq_4.listing - , subq_4.is_lux_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_8 - ) subq_9 - ) subq_10 - ) subq_11 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['is_lux_latest', 'listing'] + SELECT + subq_2.listing + , subq_2.is_lux_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE (listing__is_lux_latest) AND (booking__is_instant) + ) subq_5 + ) subq_6 + ) subq_7 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.bookings + subq_14.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_21.bookings) AS bookings + SUM(subq_13.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings',] SELECT - subq_20.bookings + subq_12.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_19.booking__is_instant - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_9.booking__is_instant AS booking__is_instant + , subq_9.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'booking__is_instant'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] + SELECT + subq_8.listing + , subq_8.booking__is_instant + , subq_8.bookings + 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_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_18.booking__is_instant - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_10.listing + , subq_10.is_lux_latest FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_14.listing AS listing - , subq_14.booking__is_instant AS booking__is_instant - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] - SELECT - subq_13.listing - , subq_13.booking__is_instant - , subq_13.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 - 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_12 - ) subq_13 - ) subq_14 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['is_lux_latest', 'listing'] - SELECT - subq_16.listing - , subq_16.is_lux_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 - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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 - ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 - WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_20 - ) subq_21 - ) subq_22 - ) subq_23 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_10 + ) subq_11 + ON + subq_9.listing = subq_11.listing + ) subq_12 + WHERE (listing__is_lux_latest) AND (booking__is_instant) + ) subq_13 + ) subq_14 + ) subq_15 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_29.booking_value + subq_19.booking_value FROM ( -- Aggregate Measures SELECT - SUM(subq_28.booking_value) AS booking_value + SUM(subq_18.booking_value) AS booking_value FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] SELECT - subq_27.booking_value + subq_17.booking_value FROM ( - -- Constrain Output with WHERE + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['booking_value', 'booking__is_instant'] SELECT - subq_26.booking__is_instant - , subq_26.booking_value + subq_16.booking__is_instant + , subq_16.booking_value FROM ( - -- Pass Only Elements: ['booking_value', 'booking__is_instant'] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_25.booking__is_instant - , subq_25.booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 - 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_24 - ) subq_25 - ) subq_26 - WHERE booking__is_instant - ) subq_27 - ) subq_28 - ) subq_29 - ) subq_30 - ) subq_31 -) subq_32 + 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_16 + ) subq_17 + WHERE booking__is_instant + ) subq_18 + ) subq_19 + ) subq_20 + ) subq_21 +) subq_22 diff --git a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0_optimized.sql index 587ebb6267..d111c88d8a 100644 --- a/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_derived_metric_rendering.py/SqlQueryPlan/DuckDB/test_nested_filters__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_44.average_booking_value) AS average_booking_value - , MAX(subq_44.bookings) AS bookings - , MAX(subq_51.booking_value) AS booking_value + MAX(subq_30.average_booking_value) AS average_booking_value + , MAX(subq_30.bookings) AS bookings + , MAX(subq_35.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value', 'bookings'] @@ -23,10 +23,9 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'bookings', 'listing__is_lux_latest', 'booking__is_instant'] SELECT - subq_35.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_35.bookings AS bookings - , subq_35.average_booking_value AS average_booking_value + subq_24.booking__is_instant AS booking__is_instant + , subq_24.bookings AS bookings + , subq_24.average_booking_value AS average_booking_value FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -37,14 +36,14 @@ FROM ( , 1 AS bookings , booking_value AS average_booking_value FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_35 + ) subq_24 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_35.listing = listings_latest_src_28000.listing_id - ) subq_40 + subq_24.listing = listings_latest_src_28000.listing_id + ) subq_27 WHERE (listing__is_lux_latest) AND (booking__is_instant) - ) subq_44 + ) subq_30 CROSS JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value',] @@ -60,8 +59,8 @@ FROM ( is_instant AS booking__is_instant , booking_value FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_47 + ) subq_32 WHERE booking__is_instant - ) subq_51 - ) subq_52 -) subq_53 + ) subq_35 + ) subq_36 +) subq_37 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 6c69cb987f..c1d99e78b1 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 @@ -1,349 +1,248 @@ -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_10.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_8.metric_time__day AS metric_time__day + , subq_7.bookings_offset_once AS bookings_offset_once FROM ( -- Time Spine SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_6.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_2.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine + SELECT + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_4 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_4.metric_time__day + ) subq_5 + ) subq_6 + ) subq_7 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day -) subq_11 + subq_8.metric_time__day - INTERVAL 2 day = subq_7.metric_time__day +) subq_10 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 fd6f165b33..5adb8c7b5a 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 @@ -5,9 +5,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 + subq_20.ds AS metric_time__day + , subq_18.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine subq_20 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -19,9 +19,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 + subq_14.ds AS metric_time__day + , SUM(subq_12.bookings) AS bookings + FROM ***************************.mf_time_spine subq_14 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -29,13 +29,13 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_12 ON - subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day + subq_14.ds - INTERVAL 5 day = subq_12.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + subq_14.ds + ) subq_17 + ) subq_18 ON - subq_22.ds - INTERVAL 2 day = subq_20.metric_time__day -) subq_23 + subq_20.ds - INTERVAL 2 day = subq_18.metric_time__day +) subq_21 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 c0b1ea0b18..c63426828d 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 @@ -1,350 +1,249 @@ -- Compute Metrics via Expressions SELECT - subq_11.metric_time__day + subq_10.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_8.metric_time__day AS metric_time__day + , subq_7.bookings_offset_once AS bookings_offset_once FROM ( -- Time Spine SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - WHERE subq_10.ds BETWEEN '2020-01-12' AND '2020-01-13' - ) subq_9 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + WHERE subq_9.ds BETWEEN '2020-01-12' AND '2020-01-13' + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_6.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_2.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine + SELECT + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_4 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_4.metric_time__day + ) subq_5 + ) subq_6 + ) subq_7 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day -) subq_11 + subq_8.metric_time__day - INTERVAL 2 day = subq_7.metric_time__day +) subq_10 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 df8acf3b4d..6c172da3f0 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 @@ -5,15 +5,15 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_21.metric_time__day AS metric_time__day - , subq_20.bookings_offset_once AS bookings_offset_once + subq_19.metric_time__day AS metric_time__day + , subq_18.bookings_offset_once AS bookings_offset_once FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_22 + FROM ***************************.mf_time_spine subq_20 WHERE ds BETWEEN '2020-01-12' AND '2020-01-13' - ) subq_21 + ) subq_19 INNER JOIN ( -- Compute Metrics via Expressions SELECT @@ -25,9 +25,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 + subq_14.ds AS metric_time__day + , SUM(subq_12.bookings) AS bookings + FROM ***************************.mf_time_spine subq_14 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -35,13 +35,13 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_12 ON - subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day + subq_14.ds - INTERVAL 5 day = subq_12.metric_time__day GROUP BY - subq_15.ds - ) subq_19 - ) subq_20 + subq_14.ds + ) subq_17 + ) subq_18 ON - subq_21.metric_time__day - INTERVAL 2 day = subq_20.metric_time__day -) subq_23 + subq_19.metric_time__day - INTERVAL 2 day = subq_18.metric_time__day +) subq_21 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 a532fe0b30..6d2b97b482 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 @@ -1,356 +1,255 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day + subq_11.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_10.metric_time__day + , subq_10.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_8.metric_time__day AS metric_time__day + , subq_7.bookings_offset_once AS bookings_offset_once FROM ( -- Time Spine SELECT - subq_10.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_10 - ) subq_9 + subq_9.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_9 + ) subq_8 INNER JOIN ( -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_6.metric_time__day , 2 * bookings AS bookings_offset_once FROM ( -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings + subq_5.metric_time__day + , subq_5.bookings FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_2.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine + SELECT + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_4 GROUP BY - subq_5.metric_time__day - ) subq_6 - ) subq_7 - ) subq_8 + subq_4.metric_time__day + ) subq_5 + ) subq_6 + ) subq_7 ON - subq_9.metric_time__day - INTERVAL 2 day = subq_8.metric_time__day - ) subq_11 + subq_8.metric_time__day - INTERVAL 2 day = subq_7.metric_time__day + ) subq_10 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_12 +) subq_11 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 767f991871..f850cc8a9b 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 @@ -10,9 +10,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 + subq_21.ds AS metric_time__day + , subq_19.bookings_offset_once AS bookings_offset_once + FROM ***************************.mf_time_spine subq_21 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 + subq_15.ds AS metric_time__day + , SUM(subq_13.bookings) AS bookings + FROM ***************************.mf_time_spine subq_15 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -34,15 +34,15 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_14 + ) subq_13 ON - subq_16.ds - INTERVAL 5 day = subq_14.metric_time__day + subq_15.ds - INTERVAL 5 day = subq_13.metric_time__day GROUP BY - subq_16.ds - ) subq_20 - ) subq_21 + subq_15.ds + ) subq_18 + ) subq_19 ON - subq_23.ds - INTERVAL 2 day = subq_21.metric_time__day - ) subq_24 + subq_21.ds - INTERVAL 2 day = subq_19.metric_time__day + ) subq_22 WHERE metric_time__day = '2020-01-12' or metric_time__day = '2020-01-13' -) subq_25 +) subq_23 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 c633e0a0db..74529cae52 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 @@ -1,345 +1,238 @@ -- Compute Metrics via Expressions SELECT - subq_9.metric_time__month + subq_7.metric_time__month , bookings_start_of_month AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__month - , subq_8.bookings AS bookings_start_of_month + subq_6.metric_time__month + , subq_6.bookings AS bookings_start_of_month FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__month - , SUM(subq_7.bookings) AS bookings + subq_5.metric_time__month + , SUM(subq_5.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__month'] SELECT - subq_6.metric_time__month - , subq_6.bookings + subq_4.metric_time__month + , subq_4.bookings FROM ( - -- Constrain Output with WHERE + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.bookings + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] + -- Time Spine SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.bookings + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Join to Time Spine Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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 - FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - WHERE DATE_TRUNC('month', subq_2.metric_time__day) = subq_2.metric_time__day - ) subq_4 - ) subq_5 - WHERE metric_time__day = '2020-01-01' - ) subq_6 - ) subq_7 + 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 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + WHERE DATE_TRUNC('month', subq_2.metric_time__day) = subq_2.metric_time__day + ) subq_4 + WHERE metric_time__day = '2020-01-01' + ) subq_5 GROUP BY - subq_7.metric_time__month - ) subq_8 -) subq_9 + subq_5.metric_time__month + ) subq_6 +) subq_7 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 bfd3b8fbce..fbe073ebef 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 @@ -14,10 +14,10 @@ FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__month', 'metric_time__day'] SELECT - subq_13.ds AS metric_time__day - , DATE_TRUNC('month', subq_13.ds) AS metric_time__month - , subq_11.bookings AS bookings - FROM ***************************.mf_time_spine subq_13 + subq_11.ds AS metric_time__day + , DATE_TRUNC('month', subq_11.ds) AS metric_time__month + , subq_9.bookings AS bookings + FROM ***************************.mf_time_spine subq_11 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -25,12 +25,12 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_9 ON - DATE_TRUNC('month', subq_13.ds) = subq_11.metric_time__day - WHERE DATE_TRUNC('month', subq_13.ds) = subq_13.ds - ) subq_15 + DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + WHERE DATE_TRUNC('month', subq_11.ds) = subq_11.ds + ) subq_12 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month -) subq_19 +) subq_15 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 8a62bf7c11..51d52f344d 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 @@ -1,339 +1,238 @@ -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day - , subq_7.metric_time__month - , subq_7.metric_time__year + subq_6.metric_time__day + , subq_6.metric_time__month + , subq_6.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_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , subq_5.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_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- 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_2.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , subq_1.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + DATE_TRUNC('month', subq_2.metric_time__day) = subq_1.metric_time__day + ) subq_4 GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - ) subq_6 -) subq_7 + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + ) subq_5 +) subq_6 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 76767e46c6..037dbf976b 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 @@ -10,11 +10,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 + subq_10.ds AS metric_time__day + , DATE_TRUNC('month', subq_10.ds) AS metric_time__month + , DATE_TRUNC('year', subq_10.ds) AS metric_time__year + , SUM(subq_8.bookings) AS bookings_start_of_month + FROM ***************************.mf_time_spine subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -22,11 +22,11 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_8 ON - DATE_TRUNC('month', subq_11.ds) = subq_9.metric_time__day + DATE_TRUNC('month', subq_10.ds) = subq_8.metric_time__day GROUP BY - subq_11.ds - , DATE_TRUNC('month', subq_11.ds) - , DATE_TRUNC('year', subq_11.ds) -) subq_15 + subq_10.ds + , DATE_TRUNC('month', subq_10.ds) + , DATE_TRUNC('year', subq_10.ds) +) subq_13 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 8734e9a26a..2a3abe48b4 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 @@ -1,129 +1,250 @@ -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_11.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 - , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_3.booking__ds__day, subq_10.booking__ds__day) AS booking__ds__day + , MAX(subq_3.bookings) AS bookings + , MAX(subq_10.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Compute Metrics via Expressions SELECT - subq_3.booking__ds__day - , subq_3.bookings + subq_2.booking__ds__day + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.booking__ds__day - , SUM(subq_2.bookings) AS bookings + subq_1.booking__ds__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'booking__ds__day'] SELECT - subq_1.booking__ds__day - , subq_1.bookings + subq_0.booking__ds__day + , subq_0.bookings 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 + ) subq_1 + GROUP BY + subq_1.booking__ds__day + ) subq_2 + ) subq_3 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.booking__ds__day + , subq_9.bookings AS bookings_at_start_of_month + FROM ( + -- Aggregate Measures + SELECT + subq_8.booking__ds__day + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'booking__ds__day'] + SELECT + subq_6.booking__ds__day AS booking__ds__day + , subq_5.bookings AS bookings + FROM ( + -- Time Spine + SELECT + subq_7.ds AS booking__ds__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 + INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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.ds__day AS metric_time__day + , subq_4.ds__week AS metric_time__week + , subq_4.ds__month AS metric_time__month + , subq_4.ds__quarter AS metric_time__quarter + , subq_4.ds__year AS metric_time__year + , subq_4.ds__extract_year AS metric_time__extract_year + , subq_4.ds__extract_quarter AS metric_time__extract_quarter + , subq_4.ds__extract_month AS metric_time__extract_month + , subq_4.ds__extract_day AS metric_time__extract_day + , subq_4.ds__extract_dow AS metric_time__extract_dow + , subq_4.ds__extract_doy AS 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 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -216,340 +337,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_0 - ) subq_1 - ) subq_2 - GROUP BY - subq_2.booking__ds__day - ) subq_3 - ) subq_4 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_11.booking__ds__day - , subq_11.bookings AS bookings_at_start_of_month - FROM ( - -- Aggregate Measures - SELECT - subq_10.booking__ds__day - , SUM(subq_10.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'booking__ds__day'] - SELECT - subq_9.booking__ds__day - , subq_9.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_7.booking__ds__day AS booking__ds__day - , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week - , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month - , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter - , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year - , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter - , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month - , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day - , EXTRACT(isodow FROM subq_7.booking__ds__day) AS booking__ds__extract_dow - , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy - , subq_6.ds__day AS ds__day - , subq_6.ds__week AS ds__week - , subq_6.ds__month AS ds__month - , subq_6.ds__quarter AS ds__quarter - , subq_6.ds__year AS ds__year - , subq_6.ds__extract_year AS ds__extract_year - , subq_6.ds__extract_quarter AS ds__extract_quarter - , subq_6.ds__extract_month AS ds__extract_month - , subq_6.ds__extract_day AS ds__extract_day - , subq_6.ds__extract_dow AS ds__extract_dow - , subq_6.ds__extract_doy AS ds__extract_doy - , subq_6.ds_partitioned__day AS ds_partitioned__day - , subq_6.ds_partitioned__week AS ds_partitioned__week - , subq_6.ds_partitioned__month AS ds_partitioned__month - , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_6.ds_partitioned__year AS ds_partitioned__year - , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_6.paid_at__day AS paid_at__day - , subq_6.paid_at__week AS paid_at__week - , subq_6.paid_at__month AS paid_at__month - , subq_6.paid_at__quarter AS paid_at__quarter - , subq_6.paid_at__year AS paid_at__year - , subq_6.paid_at__extract_year AS paid_at__extract_year - , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_6.paid_at__extract_month AS paid_at__extract_month - , subq_6.paid_at__extract_day AS paid_at__extract_day - , subq_6.paid_at__extract_dow AS paid_at__extract_dow - , subq_6.paid_at__extract_doy AS paid_at__extract_doy - , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_6.booking__paid_at__day AS booking__paid_at__day - , subq_6.booking__paid_at__week AS booking__paid_at__week - , subq_6.booking__paid_at__month AS booking__paid_at__month - , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_6.booking__paid_at__year AS booking__paid_at__year - , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_6.metric_time__day AS metric_time__day - , subq_6.metric_time__week AS metric_time__week - , subq_6.metric_time__month AS metric_time__month - , subq_6.metric_time__quarter AS metric_time__quarter - , subq_6.metric_time__year AS metric_time__year - , subq_6.metric_time__extract_year AS metric_time__extract_year - , subq_6.metric_time__extract_quarter AS metric_time__extract_quarter - , 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_dow AS metric_time__extract_dow - , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_6.listing AS listing - , subq_6.guest AS guest - , subq_6.host AS host - , subq_6.booking__listing AS booking__listing - , subq_6.booking__guest AS booking__guest - , subq_6.booking__host AS booking__host - , subq_6.is_instant AS is_instant - , subq_6.booking__is_instant AS booking__is_instant - , subq_6.bookings AS bookings - , subq_6.instant_bookings AS instant_bookings - , subq_6.booking_value AS booking_value - , subq_6.max_booking_value AS max_booking_value - , subq_6.min_booking_value AS min_booking_value - , subq_6.bookers AS bookers - , subq_6.average_booking_value AS average_booking_value - , subq_6.referred_bookings AS referred_bookings - , subq_6.median_booking_value AS median_booking_value - , subq_6.booking_value_p99 AS booking_value_p99 - , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 ( - -- Time Spine - SELECT - subq_8.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ON - DATE_TRUNC('month', subq_7.booking__ds__day) = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + ) subq_4 + ) subq_5 + ON + DATE_TRUNC('month', subq_6.booking__ds__day) = subq_5.booking__ds__day + ) subq_8 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_8.booking__ds__day + ) subq_9 + ) subq_10 ON - subq_4.booking__ds__day = subq_12.booking__ds__day + subq_3.booking__ds__day = subq_10.booking__ds__day GROUP BY - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_3.booking__ds__day, subq_10.booking__ds__day) +) subq_11 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 87a86d9826..5f435290a8 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_at_start_of_month) AS bookings_at_start_of_month + COALESCE(subq_15.booking__ds__day, subq_22.booking__ds__day) AS booking__ds__day + , MAX(subq_15.bookings) AS bookings + , MAX(subq_22.bookings_at_start_of_month) AS bookings_at_start_of_month FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -22,19 +22,19 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_13 GROUP BY booking__ds__day - ) subq_18 + ) subq_15 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS booking__ds__day - , SUM(subq_20.bookings) AS bookings_at_start_of_month - FROM ***************************.mf_time_spine subq_22 + subq_19.ds AS booking__ds__day + , SUM(subq_17.bookings) AS bookings_at_start_of_month + FROM ***************************.mf_time_spine subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,14 +42,14 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_17 ON - DATE_TRUNC('month', subq_22.ds) = subq_20.booking__ds__day + DATE_TRUNC('month', subq_19.ds) = subq_17.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + subq_19.ds + ) subq_22 ON - subq_18.booking__ds__day = subq_26.booking__ds__day + subq_15.booking__ds__day = subq_22.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_15.booking__ds__day, subq_22.booking__ds__day) +) subq_23 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 d3a6d4aadf..bc30c7b5ec 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 @@ -1,585 +1,371 @@ -- Compute Metrics via Expressions SELECT - subq_17.metric_time__month + subq_13.metric_time__month , booking_value * 0.05 / bookers AS booking_fees_last_week_per_booker_this_week FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) AS metric_time__month - , MAX(subq_9.booking_value) AS booking_value - , MAX(subq_16.bookers) AS bookers + COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) AS metric_time__month + , MAX(subq_7.booking_value) AS booking_value + , MAX(subq_12.bookers) AS bookers FROM ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__month - , subq_8.booking_value + subq_6.metric_time__month + , subq_6.booking_value FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__month - , SUM(subq_7.booking_value) AS booking_value + subq_5.metric_time__month + , SUM(subq_5.booking_value) AS booking_value FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] SELECT - subq_6.metric_time__month - , subq_6.booking_value + subq_4.metric_time__month + , subq_4.booking_value FROM ( - -- Constrain Output with WHERE + -- Join to Time Spine Dataset + -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] SELECT - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.booking_value + subq_2.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , subq_1.booking_value AS booking_value FROM ( - -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] + -- Time Spine SELECT - subq_4.metric_time__day - , subq_4.metric_time__month - , subq_4.booking_value + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Join to Time Spine Dataset + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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 - FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day - ) subq_4 - ) subq_5 - WHERE metric_time__day = '2020-01-01' - ) subq_6 - ) subq_7 + 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 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_4 + WHERE metric_time__day = '2020-01-01' + ) subq_5 GROUP BY - subq_7.metric_time__month - ) subq_8 - ) subq_9 + subq_5.metric_time__month + ) subq_6 + ) subq_7 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_15.metric_time__month - , subq_15.bookers + subq_11.metric_time__month + , subq_11.bookers FROM ( -- Aggregate Measures SELECT - subq_14.metric_time__month - , COUNT(DISTINCT subq_14.bookers) AS bookers + subq_10.metric_time__month + , COUNT(DISTINCT subq_10.bookers) AS bookers FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookers', 'metric_time__month'] SELECT - subq_13.metric_time__month - , subq_13.bookers + subq_9.metric_time__month + , subq_9.bookers FROM ( - -- Constrain Output with WHERE + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] SELECT - subq_12.metric_time__day - , subq_12.metric_time__month - , subq_12.bookers + subq_8.ds__day AS metric_time__day + , subq_8.ds__month AS metric_time__month + , subq_8.bookers FROM ( - -- Pass Only Elements: ['bookers', 'metric_time__month', 'metric_time__day'] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_11.metric_time__day - , subq_11.metric_time__month - , subq_11.bookers - 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_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 - 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_10 - ) subq_11 - ) subq_12 - WHERE metric_time__day = '2020-01-01' - ) subq_13 - ) subq_14 + 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_8 + ) subq_9 + WHERE metric_time__day = '2020-01-01' + ) subq_10 GROUP BY - subq_14.metric_time__month - ) subq_15 - ) subq_16 + subq_10.metric_time__month + ) subq_11 + ) subq_12 ON - subq_9.metric_time__month = subq_16.metric_time__month + subq_7.metric_time__month = subq_12.metric_time__month GROUP BY - COALESCE(subq_9.metric_time__month, subq_16.metric_time__month) -) subq_17 + COALESCE(subq_7.metric_time__month, subq_12.metric_time__month) +) subq_13 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 0def7f4cf6..b3d6374bd2 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) AS metric_time__month - , MAX(subq_27.booking_value) AS booking_value - , MAX(subq_34.bookers) AS bookers + COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month + , MAX(subq_21.booking_value) AS booking_value + , MAX(subq_26.bookers) AS bookers FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__month'] @@ -20,19 +20,19 @@ FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['booking_value', 'metric_time__month', 'metric_time__day'] SELECT - subq_21.ds AS metric_time__day - , DATE_TRUNC('month', subq_21.ds) AS metric_time__month + subq_17.ds AS metric_time__day + , DATE_TRUNC('month', subq_17.ds) AS metric_time__month , bookings_source_src_28000.booking_value AS booking_value - FROM ***************************.mf_time_spine subq_21 + FROM ***************************.mf_time_spine subq_17 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_21.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) - ) subq_23 + subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + ) subq_18 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_27 + ) subq_21 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookers', 'metric_time__month'] @@ -50,13 +50,13 @@ FROM ( , DATE_TRUNC('month', ds) AS metric_time__month , guest_id AS bookers FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_30 + ) subq_23 WHERE metric_time__day = '2020-01-01' GROUP BY metric_time__month - ) subq_34 + ) subq_26 ON - subq_27.metric_time__month = subq_34.metric_time__month + subq_21.metric_time__month = subq_26.metric_time__month GROUP BY - COALESCE(subq_27.metric_time__month, subq_34.metric_time__month) -) subq_35 + COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) +) subq_27 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 92f1870c03..3be59e63dd 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 @@ -1,472 +1,146 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.metric_time__month - , subq_13.metric_time__year + subq_11.metric_time__day + , subq_11.metric_time__month + , subq_11.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_6.metric_time__day, subq_10.metric_time__day) AS metric_time__day + , COALESCE(subq_6.metric_time__month, subq_10.metric_time__month) AS metric_time__month + , COALESCE(subq_6.metric_time__year, subq_10.metric_time__year) AS metric_time__year + , MAX(subq_6.booking_value) AS booking_value + , MAX(subq_10.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_5.metric_time__day + , subq_5.metric_time__month + , subq_5.metric_time__year + , subq_5.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_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + , SUM(subq_4.booking_value) AS booking_value FROM ( + -- Join to Time Spine Dataset -- 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_2.metric_time__day AS metric_time__day + , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month + , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year + , subq_1.booking_value AS booking_value FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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 - FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day - ) subq_4 - ) subq_5 - GROUP BY - subq_5.metric_time__day - , subq_5.metric_time__month - , subq_5.metric_time__year - ) subq_6 - ) subq_7 - 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 - 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 - 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 - FROM ( + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -559,25 +233,149 @@ 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_0 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 1 week = subq_1.metric_time__day + ) subq_4 + GROUP BY + subq_4.metric_time__day + , subq_4.metric_time__month + , subq_4.metric_time__year + ) subq_5 + ) subq_6 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.metric_time__day + , subq_9.metric_time__month + , subq_9.metric_time__year + , subq_9.bookers + FROM ( + -- Aggregate Measures + SELECT + subq_8.metric_time__day + , subq_8.metric_time__month + , subq_8.metric_time__year + , COUNT(DISTINCT subq_8.bookers) AS bookers + FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'metric_time__day', 'metric_time__month', 'metric_time__year'] + SELECT + subq_7.ds__day AS metric_time__day + , subq_7.ds__month AS metric_time__month + , subq_7.ds__year AS metric_time__year + , subq_7.bookers + 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_7 + ) subq_8 GROUP BY - subq_10.metric_time__day - , subq_10.metric_time__month - , subq_10.metric_time__year - ) subq_11 - ) subq_12 + subq_8.metric_time__day + , subq_8.metric_time__month + , subq_8.metric_time__year + ) subq_9 + ) subq_10 ON ( - subq_7.metric_time__day = subq_12.metric_time__day + subq_6.metric_time__day = subq_10.metric_time__day ) AND ( - subq_7.metric_time__month = subq_12.metric_time__month + subq_6.metric_time__month = subq_10.metric_time__month ) AND ( - subq_7.metric_time__year = subq_12.metric_time__year + subq_6.metric_time__year = subq_10.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_6.metric_time__day, subq_10.metric_time__day) + , COALESCE(subq_6.metric_time__month, subq_10.metric_time__month) + , COALESCE(subq_6.metric_time__year, subq_10.metric_time__year) +) subq_11 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 7a9df9d3d5..c1e8152aad 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 @@ -7,31 +7,31 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) AS metric_time__month - , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) AS metric_time__year - , MAX(subq_21.booking_value) AS booking_value - , MAX(subq_26.bookers) AS bookers + COALESCE(subq_18.metric_time__day, subq_22.metric_time__day) AS metric_time__day + , COALESCE(subq_18.metric_time__month, subq_22.metric_time__month) AS metric_time__month + , COALESCE(subq_18.metric_time__year, subq_22.metric_time__year) AS metric_time__year + , MAX(subq_18.booking_value) AS booking_value + , MAX(subq_22.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 + subq_15.ds AS metric_time__day + , DATE_TRUNC('month', subq_15.ds) AS metric_time__month + , DATE_TRUNC('year', subq_15.ds) AS metric_time__year , SUM(bookings_source_src_28000.booking_value) AS booking_value - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine subq_15 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON - subq_17.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) + subq_15.ds - INTERVAL 1 week = DATE_TRUNC('day', bookings_source_src_28000.ds) GROUP BY - subq_17.ds - , DATE_TRUNC('month', subq_17.ds) - , DATE_TRUNC('year', subq_17.ds) - ) subq_21 + subq_15.ds + , DATE_TRUNC('month', subq_15.ds) + , DATE_TRUNC('year', subq_15.ds) + ) subq_18 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -48,17 +48,17 @@ FROM ( DATE_TRUNC('day', ds) , DATE_TRUNC('month', ds) , DATE_TRUNC('year', ds) - ) subq_26 + ) subq_22 ON ( - subq_21.metric_time__day = subq_26.metric_time__day + subq_18.metric_time__day = subq_22.metric_time__day ) AND ( - subq_21.metric_time__month = subq_26.metric_time__month + subq_18.metric_time__month = subq_22.metric_time__month ) AND ( - subq_21.metric_time__year = subq_26.metric_time__year + subq_18.metric_time__year = subq_22.metric_time__year ) GROUP BY - COALESCE(subq_21.metric_time__day, subq_26.metric_time__day) - , COALESCE(subq_21.metric_time__month, subq_26.metric_time__month) - , COALESCE(subq_21.metric_time__year, subq_26.metric_time__year) -) subq_27 + COALESCE(subq_18.metric_time__day, subq_22.metric_time__day) + , COALESCE(subq_18.metric_time__month, subq_22.metric_time__month) + , COALESCE(subq_18.metric_time__year, subq_22.metric_time__year) +) subq_23 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 10520fd03d..e48a1254c9 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 @@ -1,129 +1,250 @@ -- Compute Metrics via Expressions SELECT - subq_13.booking__ds__day + subq_11.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 - , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_3.booking__ds__day, subq_10.booking__ds__day) AS booking__ds__day + , MAX(subq_3.bookings) AS bookings + , MAX(subq_10.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_3.booking__ds__day - , subq_3.bookings + subq_2.booking__ds__day + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.booking__ds__day - , SUM(subq_2.bookings) AS bookings + subq_1.booking__ds__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'booking__ds__day'] SELECT - subq_1.booking__ds__day - , subq_1.bookings + subq_0.booking__ds__day + , subq_0.bookings 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 + ) subq_1 + GROUP BY + subq_1.booking__ds__day + ) subq_2 + ) subq_3 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.booking__ds__day + , subq_9.bookings AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + SELECT + subq_8.booking__ds__day + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'booking__ds__day'] + SELECT + subq_6.booking__ds__day AS booking__ds__day + , subq_5.bookings AS bookings + FROM ( + -- Time Spine + SELECT + subq_7.ds AS booking__ds__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 + INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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.ds__day AS metric_time__day + , subq_4.ds__week AS metric_time__week + , subq_4.ds__month AS metric_time__month + , subq_4.ds__quarter AS metric_time__quarter + , subq_4.ds__year AS metric_time__year + , subq_4.ds__extract_year AS metric_time__extract_year + , subq_4.ds__extract_quarter AS metric_time__extract_quarter + , subq_4.ds__extract_month AS metric_time__extract_month + , subq_4.ds__extract_day AS metric_time__extract_day + , subq_4.ds__extract_dow AS metric_time__extract_dow + , subq_4.ds__extract_doy AS 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 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -216,340 +337,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_0 - ) subq_1 - ) subq_2 - GROUP BY - subq_2.booking__ds__day - ) subq_3 - ) subq_4 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_11.booking__ds__day - , subq_11.bookings AS bookings_2_weeks_ago - FROM ( - -- Aggregate Measures - SELECT - subq_10.booking__ds__day - , SUM(subq_10.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'booking__ds__day'] - SELECT - subq_9.booking__ds__day - , subq_9.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_7.booking__ds__day AS booking__ds__day - , DATE_TRUNC('week', subq_7.booking__ds__day) AS booking__ds__week - , DATE_TRUNC('month', subq_7.booking__ds__day) AS booking__ds__month - , DATE_TRUNC('quarter', subq_7.booking__ds__day) AS booking__ds__quarter - , DATE_TRUNC('year', subq_7.booking__ds__day) AS booking__ds__year - , EXTRACT(year FROM subq_7.booking__ds__day) AS booking__ds__extract_year - , EXTRACT(quarter FROM subq_7.booking__ds__day) AS booking__ds__extract_quarter - , EXTRACT(month FROM subq_7.booking__ds__day) AS booking__ds__extract_month - , EXTRACT(day FROM subq_7.booking__ds__day) AS booking__ds__extract_day - , EXTRACT(isodow FROM subq_7.booking__ds__day) AS booking__ds__extract_dow - , EXTRACT(doy FROM subq_7.booking__ds__day) AS booking__ds__extract_doy - , subq_6.ds__day AS ds__day - , subq_6.ds__week AS ds__week - , subq_6.ds__month AS ds__month - , subq_6.ds__quarter AS ds__quarter - , subq_6.ds__year AS ds__year - , subq_6.ds__extract_year AS ds__extract_year - , subq_6.ds__extract_quarter AS ds__extract_quarter - , subq_6.ds__extract_month AS ds__extract_month - , subq_6.ds__extract_day AS ds__extract_day - , subq_6.ds__extract_dow AS ds__extract_dow - , subq_6.ds__extract_doy AS ds__extract_doy - , subq_6.ds_partitioned__day AS ds_partitioned__day - , subq_6.ds_partitioned__week AS ds_partitioned__week - , subq_6.ds_partitioned__month AS ds_partitioned__month - , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_6.ds_partitioned__year AS ds_partitioned__year - , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_6.paid_at__day AS paid_at__day - , subq_6.paid_at__week AS paid_at__week - , subq_6.paid_at__month AS paid_at__month - , subq_6.paid_at__quarter AS paid_at__quarter - , subq_6.paid_at__year AS paid_at__year - , subq_6.paid_at__extract_year AS paid_at__extract_year - , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_6.paid_at__extract_month AS paid_at__extract_month - , subq_6.paid_at__extract_day AS paid_at__extract_day - , subq_6.paid_at__extract_dow AS paid_at__extract_dow - , subq_6.paid_at__extract_doy AS paid_at__extract_doy - , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_6.booking__paid_at__day AS booking__paid_at__day - , subq_6.booking__paid_at__week AS booking__paid_at__week - , subq_6.booking__paid_at__month AS booking__paid_at__month - , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_6.booking__paid_at__year AS booking__paid_at__year - , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_6.metric_time__day AS metric_time__day - , subq_6.metric_time__week AS metric_time__week - , subq_6.metric_time__month AS metric_time__month - , subq_6.metric_time__quarter AS metric_time__quarter - , subq_6.metric_time__year AS metric_time__year - , subq_6.metric_time__extract_year AS metric_time__extract_year - , subq_6.metric_time__extract_quarter AS metric_time__extract_quarter - , 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_dow AS metric_time__extract_dow - , subq_6.metric_time__extract_doy AS metric_time__extract_doy - , subq_6.listing AS listing - , subq_6.guest AS guest - , subq_6.host AS host - , subq_6.booking__listing AS booking__listing - , subq_6.booking__guest AS booking__guest - , subq_6.booking__host AS booking__host - , subq_6.is_instant AS is_instant - , subq_6.booking__is_instant AS booking__is_instant - , subq_6.bookings AS bookings - , subq_6.instant_bookings AS instant_bookings - , subq_6.booking_value AS booking_value - , subq_6.max_booking_value AS max_booking_value - , subq_6.min_booking_value AS min_booking_value - , subq_6.bookers AS bookers - , subq_6.average_booking_value AS average_booking_value - , subq_6.referred_bookings AS referred_bookings - , subq_6.median_booking_value AS median_booking_value - , subq_6.booking_value_p99 AS booking_value_p99 - , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 ( - -- Time Spine - SELECT - subq_8.ds AS booking__ds__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ON - subq_7.booking__ds__day - INTERVAL 14 day = subq_6.booking__ds__day - ) subq_9 - ) subq_10 + ) subq_4 + ) subq_5 + ON + subq_6.booking__ds__day - INTERVAL 14 day = subq_5.booking__ds__day + ) subq_8 GROUP BY - subq_10.booking__ds__day - ) subq_11 - ) subq_12 + subq_8.booking__ds__day + ) subq_9 + ) subq_10 ON - subq_4.booking__ds__day = subq_12.booking__ds__day + subq_3.booking__ds__day = subq_10.booking__ds__day GROUP BY - COALESCE(subq_4.booking__ds__day, subq_12.booking__ds__day) -) subq_13 + COALESCE(subq_3.booking__ds__day, subq_10.booking__ds__day) +) subq_11 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 cacae6cc3a..372d0ff26e 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) AS booking__ds__day - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_15.booking__ds__day, subq_22.booking__ds__day) AS booking__ds__day + , MAX(subq_15.bookings) AS bookings + , MAX(subq_22.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -22,19 +22,19 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_13 GROUP BY booking__ds__day - ) subq_18 + ) subq_15 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__ds__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.ds AS booking__ds__day - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + subq_19.ds AS booking__ds__day + , SUM(subq_17.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,14 +42,14 @@ FROM ( DATE_TRUNC('day', ds) AS booking__ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_17 ON - subq_22.ds - INTERVAL 14 day = subq_20.booking__ds__day + subq_19.ds - INTERVAL 14 day = subq_17.booking__ds__day GROUP BY - subq_22.ds - ) subq_26 + subq_19.ds + ) subq_22 ON - subq_18.booking__ds__day = subq_26.booking__ds__day + subq_15.booking__ds__day = subq_22.booking__ds__day GROUP BY - COALESCE(subq_18.booking__ds__day, subq_26.booking__ds__day) -) subq_27 + COALESCE(subq_15.booking__ds__day, subq_22.booking__ds__day) +) subq_23 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 a3c227a694..701492c3df 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 @@ -1,330 +1,229 @@ -- Compute Metrics via Expressions SELECT - subq_7.metric_time__day + subq_6.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_5.metric_time__day + , subq_5.bookings AS bookings_5_days_ago FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_2.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__day) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + WHERE subq_3.ds BETWEEN '2019-12-19' AND '2020-01-02' + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - WHERE subq_3.ds BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + subq_2.metric_time__day - INTERVAL 5 day = subq_1.metric_time__day + ) subq_4 GROUP BY - subq_5.metric_time__day - ) subq_6 -) subq_7 + subq_4.metric_time__day + ) subq_5 +) subq_6 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 d1f30b244b..15fa87c414 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 @@ -8,15 +8,15 @@ FROM ( -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day AS metric_time__day - , SUM(subq_9.bookings) AS bookings_5_days_ago + subq_9.metric_time__day AS metric_time__day + , SUM(subq_8.bookings) AS bookings_5_days_ago FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_11 + FROM ***************************.mf_time_spine subq_10 WHERE ds BETWEEN '2019-12-19' AND '2020-01-02' - ) subq_10 + ) subq_9 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -24,9 +24,9 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_8 ON - subq_10.metric_time__day - INTERVAL 5 day = subq_9.metric_time__day + subq_9.metric_time__day - INTERVAL 5 day = subq_8.metric_time__day GROUP BY - subq_10.metric_time__day -) subq_15 + subq_9.metric_time__day +) subq_13 diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql index d736ad0d03..601f27a4a4 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0.sql @@ -1,229 +1,141 @@ +-- Constrain Output with WHERE -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_2.listing__is_lux_latest + , subq_2.user__home_state_latest FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.user__home_state_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_1.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' 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.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - FULL OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_1.user - , subq_1.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 - ON - subq_0.user = subq_2.user - ) subq_3 - WHERE user__home_state_latest = 'us' -) subq_4 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + FULL OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_1 + ON + subq_0.user = subq_1.user +) subq_2 +WHERE user__home_state_latest = 'us' GROUP BY - subq_4.listing__is_lux_latest - , subq_4.user__home_state_latest + subq_2.listing__is_lux_latest + , subq_2.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql index e54eaffeb6..07dadd71e7 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimension_values_with_a_join_and_a_filter__plan0_optimized.sql @@ -13,7 +13,7 @@ FROM ( ***************************.dim_users_latest users_latest_src_28000 ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id -) subq_8 +) subq_5 WHERE user__home_state_latest = 'us' GROUP BY listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql index 0962aa9958..f78c43b635 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0.sql @@ -1,167 +1,77 @@ +-- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT - subq_3.listing__is_lux_latest - , subq_3.user__home_state_latest + subq_0.listing__is_lux_latest AS listing__is_lux_latest FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' 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.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_2.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - FULL OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_1.user - , subq_1.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_1 - ) subq_2 - ON - subq_0.user = subq_2.user -) subq_3 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 +FULL OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 +) subq_1 +ON + subq_0.user = subq_1.user GROUP BY - subq_3.listing__is_lux_latest - , subq_3.user__home_state_latest + subq_0.listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql index 96c5d5bb3a..395ae8fe1f 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/DuckDB/test_dimensions_requiring_join__plan0_optimized.sql @@ -2,7 +2,6 @@ -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest'] SELECT listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 FULL OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 @@ -10,4 +9,3 @@ ON listings_latest_src_28000.user_id = users_latest_src_28000.user_id GROUP BY listings_latest_src_28000.is_lux - , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimension_values_with_a_join_and_a_filter__plan0.xml b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimension_values_with_a_join_and_a_filter__plan0.xml index 610ab841f2..35fcba7662 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimension_values_with_a_join_and_a_filter__plan0.xml +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimension_values_with_a_join_and_a_filter__plan0.xml @@ -1,810 +1,436 @@ - + + - - - - - - - - - - + + + + + + + + + + - - - - - - - + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - + - - + + - + - - + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml index 9db49ce437..97b2aa57f5 100644 --- a/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml +++ b/tests_metricflow/snapshots/test_distinct_values_to_sql.py/SqlQueryPlan/test_dimensions_requiring_join__plan0.xml @@ -1,552 +1,188 @@ - + + - - - - - - - - - + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + 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 e30f09d486..1b4be7943e 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 @@ -1,341 +1,240 @@ -- 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_8.metric_time__day + , COALESCE(subq_8.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_6.bookers AS bookers + subq_6.metric_time__day AS metric_time__day + , subq_5.bookers AS bookers FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 + subq_7.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , COUNT(DISTINCT subq_5.bookers) AS bookers + subq_4.metric_time__day + , COUNT(DISTINCT subq_4.bookers) AS bookers FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookers + subq_2.metric_time__day AS metric_time__day + , subq_1.bookers AS bookers FROM ( - -- Join Self Over Time Range + -- Time Spine + SELECT + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Time Spine + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day - ) - ) subq_4 - ) subq_5 + 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 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day + ) + ) subq_4 GROUP BY - subq_5.metric_time__day - ) subq_6 + subq_4.metric_time__day + ) subq_5 ON - subq_7.metric_time__day = subq_6.metric_time__day -) subq_9 + subq_6.metric_time__day = subq_5.metric_time__day +) subq_8 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 80c8cdd0e9..c1c5812180 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 @@ -5,28 +5,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 + subq_16.ds AS metric_time__day + , subq_14.bookers AS bookers + FROM ***************************.mf_time_spine subq_16 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_12.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_12 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_12.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_12.ds - INTERVAL 2 day ) GROUP BY - subq_13.ds - ) subq_16 + subq_12.ds + ) subq_14 ON - subq_18.ds = subq_16.metric_time__day -) subq_19 + subq_16.ds = subq_14.metric_time__day +) subq_17 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 eb0612129b..ecfe0495ec 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 @@ -1,569 +1,367 @@ -- Compute Metrics via Expressions SELECT - subq_16.metric_time__day + subq_14.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_6.metric_time__day, subq_13.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_6.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , MAX(subq_13.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_5.metric_time__day + , COALESCE(subq_5.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_3.bookings AS bookings + subq_3.metric_time__day AS metric_time__day + , subq_2.bookings AS bookings FROM ( -- Time Spine SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_4.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_4 + ) subq_3 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 + subq_1.metric_time__day + ) subq_2 ON - subq_4.metric_time__day = subq_3.metric_time__day - ) subq_6 - ) subq_7 + subq_3.metric_time__day = subq_2.metric_time__day + ) subq_5 + ) subq_6 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_14.metric_time__day - , subq_14.bookings AS bookings_2_weeks_ago + subq_12.metric_time__day + , subq_12.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_13.metric_time__day - , SUM(subq_13.bookings) AS bookings + subq_11.metric_time__day + , SUM(subq_11.bookings) AS bookings FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_12.metric_time__day - , subq_12.bookings + subq_9.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_10.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_10.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_10.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_10.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_10.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_10.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_10.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_10.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_10.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_10.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_10.metric_time__day) AS metric_time__extract_doy - , 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.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 AS metric_time__day + FROM ***************************.mf_time_spine subq_10 + ) subq_9 + INNER JOIN ( + -- 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.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.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.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 FROM ( - -- Time Spine - SELECT - subq_11.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_11 - ) subq_10 - INNER JOIN ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' 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 - 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_8 - ) subq_9 - ON - subq_10.metric_time__day - INTERVAL 14 day = subq_9.metric_time__day - ) subq_12 - ) subq_13 + 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_7 + ) subq_8 + ON + subq_9.metric_time__day - INTERVAL 14 day = subq_8.metric_time__day + ) subq_11 GROUP BY - subq_13.metric_time__day - ) subq_14 - ) subq_15 + subq_11.metric_time__day + ) subq_12 + ) subq_13 ON - subq_7.metric_time__day = subq_15.metric_time__day + subq_6.metric_time__day = subq_13.metric_time__day GROUP BY - COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) -) subq_16 + COALESCE(subq_6.metric_time__day, subq_13.metric_time__day) +) subq_14 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 918daa9a18..001213c057 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) AS metric_time__day - , COALESCE(MAX(subq_24.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , MAX(subq_32.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_21.metric_time__day, subq_28.metric_time__day) AS metric_time__day + , COALESCE(MAX(subq_21.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , MAX(subq_28.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -16,9 +16,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 + subq_19.ds AS metric_time__day + , subq_17.bookings AS bookings + FROM ***************************.mf_time_spine subq_19 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -32,23 +32,23 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_19 + ) subq_16 GROUP BY metric_time__day - ) subq_20 + ) subq_17 ON - subq_22.ds = subq_20.metric_time__day - ) subq_23 - ) subq_24 + subq_19.ds = subq_17.metric_time__day + ) subq_20 + ) subq_21 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__day'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_28.ds AS metric_time__day - , SUM(subq_26.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_28 + subq_25.ds AS metric_time__day + , SUM(subq_23.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine subq_25 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -56,14 +56,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_23 ON - subq_28.ds - INTERVAL 14 day = subq_26.metric_time__day + subq_25.ds - INTERVAL 14 day = subq_23.metric_time__day GROUP BY - subq_28.ds - ) subq_32 + subq_25.ds + ) subq_28 ON - subq_24.metric_time__day = subq_32.metric_time__day + subq_21.metric_time__day = subq_28.metric_time__day GROUP BY - COALESCE(subq_24.metric_time__day, subq_32.metric_time__day) -) subq_33 + COALESCE(subq_21.metric_time__day, subq_28.metric_time__day) +) subq_29 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 007e38a03c..134dc3fa1b 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 @@ -1,353 +1,246 @@ -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , COALESCE(subq_10.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 ( -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_9.metric_time__day - , subq_9.bookings + subq_7.metric_time__day + , subq_7.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_7.metric_time__day AS metric_time__day - , subq_6.bookings AS bookings + subq_5.metric_time__day AS metric_time__day + , subq_4.bookings AS bookings FROM ( -- Time Spine SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - WHERE subq_8.ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_7 + 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 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_5.metric_time__day - , SUM(subq_5.bookings) AS bookings + subq_3.metric_time__day + , SUM(subq_3.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_4.metric_time__day - , subq_4.bookings + subq_2.metric_time__day + , subq_2.bookings FROM ( - -- Constrain Output with WHERE + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__week'] SELECT - subq_3.metric_time__day - , subq_3.metric_time__week - , subq_3.bookings + subq_1.metric_time__day + , subq_1.metric_time__week + , subq_1.bookings FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day', 'metric_time__week'] + -- Metric Time Dimension 'ds' SELECT - subq_2.metric_time__day - , subq_2.metric_time__week - , subq_2.bookings + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.ds_partitioned__day - , subq_1.ds_partitioned__week - , subq_1.ds_partitioned__month - , subq_1.ds_partitioned__quarter - , subq_1.ds_partitioned__year - , subq_1.ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy - , subq_1.paid_at__day - , subq_1.paid_at__week - , subq_1.paid_at__month - , subq_1.paid_at__quarter - , subq_1.paid_at__year - , subq_1.paid_at__extract_year - , subq_1.paid_at__extract_quarter - , subq_1.paid_at__extract_month - , subq_1.paid_at__extract_day - , subq_1.paid_at__extract_dow - , subq_1.paid_at__extract_doy - , subq_1.booking__ds__day - , subq_1.booking__ds__week - , subq_1.booking__ds__month - , subq_1.booking__ds__quarter - , subq_1.booking__ds__year - , subq_1.booking__ds__extract_year - , subq_1.booking__ds__extract_quarter - , subq_1.booking__ds__extract_month - , subq_1.booking__ds__extract_day - , subq_1.booking__ds__extract_dow - , subq_1.booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day - , subq_1.booking__paid_at__week - , subq_1.booking__paid_at__month - , subq_1.booking__paid_at__quarter - , subq_1.booking__paid_at__year - , subq_1.booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.listing - , subq_1.guest - , subq_1.host - , subq_1.booking__listing - , subq_1.booking__guest - , subq_1.booking__host - , subq_1.is_instant - , subq_1.booking__is_instant - , subq_1.bookings - , subq_1.instant_bookings - , subq_1.booking_value - , subq_1.max_booking_value - , subq_1.min_booking_value - , subq_1.bookers - , subq_1.average_booking_value - , subq_1.referred_bookings - , subq_1.median_booking_value - , subq_1.booking_value_p99 - , subq_1.discrete_booking_value_p99 - , subq_1.approximate_continuous_booking_value_p99 - , subq_1.approximate_discrete_booking_value_p99 - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_2 - ) subq_3 - WHERE metric_time__week > '2020-01-01' - ) subq_4 - ) subq_5 + 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 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) subq_2 + WHERE metric_time__week > '2020-01-01' + ) subq_3 GROUP BY - subq_5.metric_time__day - ) subq_6 + subq_3.metric_time__day + ) subq_4 ON - subq_7.metric_time__day = subq_6.metric_time__day - ) subq_9 - WHERE subq_9.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_10 + 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 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 ae0e42a39e..5ea26cc5bf 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 @@ -6,15 +6,15 @@ FROM ( -- Join to Time Spine Dataset -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_18.metric_time__day AS metric_time__day - , subq_17.bookings AS bookings + subq_14.metric_time__day AS metric_time__day + , subq_13.bookings AS bookings FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_19 + FROM ***************************.mf_time_spine subq_15 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_18 + ) subq_14 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -33,12 +33,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_14 + ) subq_11 WHERE metric_time__week > '2020-01-01' GROUP BY metric_time__day - ) subq_17 + ) subq_13 ON - subq_18.metric_time__day = subq_17.metric_time__day - WHERE subq_18.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' -) subq_21 + 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 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 bd106944b5..624f50683c 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 @@ -1,227 +1,126 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_5.metric_time__day + , COALESCE(subq_5.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_3.bookings AS bookings + subq_3.metric_time__day AS metric_time__day + , subq_2.bookings AS bookings FROM ( -- Time Spine SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_4.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_4 + ) subq_3 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 + subq_1.metric_time__day + ) subq_2 ON - subq_4.metric_time__day = subq_3.metric_time__day -) subq_6 + subq_3.metric_time__day = subq_2.metric_time__day +) subq_5 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 591b4614fd..1ef43bbdfa 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 @@ -5,9 +5,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 + subq_10.ds AS metric_time__day + , subq_8.bookings AS bookings + FROM ***************************.mf_time_spine subq_10 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -21,10 +21,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_7 GROUP BY metric_time__day - ) subq_10 + ) subq_8 ON - subq_12.ds = subq_10.metric_time__day -) subq_13 + subq_10.ds = subq_8.metric_time__day +) subq_11 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 5c3b8e6f6c..f2aecb0a14 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 @@ -1,229 +1,128 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__month - , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 + subq_5.metric_time__month + , COALESCE(subq_5.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_3.bookings AS bookings + subq_3.metric_time__month AS metric_time__month + , subq_2.bookings AS bookings FROM ( -- Time Spine SELECT - DATE_TRUNC('month', subq_5.ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_5 + DATE_TRUNC('month', subq_4.ds) AS metric_time__month + FROM ***************************.mf_time_spine subq_4 GROUP BY - DATE_TRUNC('month', subq_5.ds) - ) subq_4 + DATE_TRUNC('month', subq_4.ds) + ) subq_3 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_2.metric_time__month - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__month + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__month'] SELECT - subq_1.metric_time__month - , subq_1.bookings + subq_0.ds__month AS metric_time__month + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__month - ) subq_3 + subq_1.metric_time__month + ) subq_2 ON - subq_4.metric_time__month = subq_3.metric_time__month -) subq_6 + subq_3.metric_time__month = subq_2.metric_time__month +) subq_5 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 aad33e7f07..c48d709ab6 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 @@ -5,16 +5,16 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_11.metric_time__month AS metric_time__month - , subq_10.bookings AS bookings + subq_9.metric_time__month AS metric_time__month + , subq_8.bookings AS bookings FROM ( -- Time Spine SELECT DATE_TRUNC('month', ds) AS metric_time__month - FROM ***************************.mf_time_spine subq_12 + FROM ***************************.mf_time_spine subq_10 GROUP BY DATE_TRUNC('month', ds) - ) subq_11 + ) subq_9 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -28,10 +28,10 @@ FROM ( DATE_TRUNC('month', ds) AS metric_time__month , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_7 GROUP BY metric_time__month - ) subq_10 + ) subq_8 ON - subq_11.metric_time__month = subq_10.metric_time__month -) subq_13 + subq_9.metric_time__month = subq_8.metric_time__month +) subq_11 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql index de0dc126a4..c728022137 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0.sql @@ -1,213 +1,112 @@ -- Compute Metrics via Expressions SELECT - subq_3.booking__is_instant - , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0 + subq_2.booking__is_instant + , COALESCE(subq_2.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Aggregate Measures SELECT - subq_2.booking__is_instant - , SUM(subq_2.bookings) AS bookings + subq_1.booking__is_instant + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'booking__is_instant'] SELECT - subq_1.booking__is_instant - , subq_1.bookings + subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.booking__is_instant -) subq_3 + subq_1.booking__is_instant +) subq_2 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql index ca9a0d3470..e9d4d6c08c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_categorical_dimension__plan0_optimized.sql @@ -15,7 +15,7 @@ FROM ( is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_6 + ) subq_4 GROUP BY booking__is_instant -) subq_7 +) subq_5 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql index 5186364387..3a40a9dd1e 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_non_metric_time__plan0.sql @@ -1,213 +1,112 @@ -- Compute Metrics via Expressions SELECT - subq_3.booking__paid_at__day - , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0 + subq_2.booking__paid_at__day + , COALESCE(subq_2.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Aggregate Measures SELECT - subq_2.booking__paid_at__day - , SUM(subq_2.bookings) AS bookings + subq_1.booking__paid_at__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'booking__paid_at__day'] SELECT - subq_1.booking__paid_at__day - , subq_1.bookings + subq_0.booking__paid_at__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.booking__paid_at__day -) subq_3 + subq_1.booking__paid_at__day +) subq_2 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql index bc2036b9bd..3aed43087c 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_with_0_with_non_metric_time__plan0_optimized.sql @@ -15,7 +15,7 @@ FROM ( DATE_TRUNC('day', paid_at) AS booking__paid_at__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_6 + ) subq_4 GROUP BY booking__paid_at__day -) subq_7 +) subq_5 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_without_time_spine__plan0.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_without_time_spine__plan0.sql index 8d0af3eb4c..1ffa783547 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_without_time_spine__plan0.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_without_time_spine__plan0.sql @@ -1,213 +1,112 @@ -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , COALESCE(subq_3.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine + subq_2.metric_time__day + , COALESCE(subq_2.bookings, 0) AS bookings_fill_nulls_with_0_without_time_spine FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day -) subq_3 + subq_1.metric_time__day +) subq_2 diff --git a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql index 3af90d64a2..b6ff5d531a 100644 --- a/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_fill_nulls_with_rendering.py/SqlQueryPlan/DuckDB/test_simple_fill_nulls_without_time_spine__plan0_optimized.sql @@ -15,7 +15,7 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_6 + ) subq_4 GROUP BY metric_time__day -) subq_7 +) subq_5 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 a0db6aa138..a01fb9df25 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 @@ -1,129 +1,250 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__extract_dow + subq_11.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 - , MAX(subq_4.bookings) AS bookings - , MAX(subq_12.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_3.metric_time__extract_dow, subq_10.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_3.bookings) AS bookings + , MAX(subq_10.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__extract_dow - , subq_3.bookings + subq_2.metric_time__extract_dow + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__extract_dow - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__extract_dow + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] SELECT - subq_1.metric_time__extract_dow - , subq_1.bookings + subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.bookings 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 + ) subq_1 + GROUP BY + subq_1.metric_time__extract_dow + ) subq_2 + ) subq_3 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_9.metric_time__extract_dow + , subq_9.bookings AS bookings_2_weeks_ago + FROM ( + -- Aggregate Measures + SELECT + subq_8.metric_time__extract_dow + , SUM(subq_8.bookings) AS bookings + FROM ( + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] + SELECT + EXTRACT(isodow FROM subq_6.metric_time__day) AS metric_time__extract_dow + , subq_5.bookings AS bookings + FROM ( + -- Time Spine + SELECT + subq_7.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_7 + ) subq_6 + INNER JOIN ( -- Metric Time Dimension 'ds' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 + 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.ds__day AS metric_time__day + , subq_4.ds__week AS metric_time__week + , subq_4.ds__month AS metric_time__month + , subq_4.ds__quarter AS metric_time__quarter + , subq_4.ds__year AS metric_time__year + , subq_4.ds__extract_year AS metric_time__extract_year + , subq_4.ds__extract_quarter AS metric_time__extract_quarter + , subq_4.ds__extract_month AS metric_time__extract_month + , subq_4.ds__extract_day AS metric_time__extract_day + , subq_4.ds__extract_dow AS metric_time__extract_dow + , subq_4.ds__extract_doy AS 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 FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -216,340 +337,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_0 - ) subq_1 - ) subq_2 - GROUP BY - subq_2.metric_time__extract_dow - ) subq_3 - ) subq_4 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_11.metric_time__extract_dow - , subq_11.bookings AS bookings_2_weeks_ago - FROM ( - -- Aggregate Measures - SELECT - subq_10.metric_time__extract_dow - , SUM(subq_10.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] - SELECT - subq_9.metric_time__extract_dow - , subq_9.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_7.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_7.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_7.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_7.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_7.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_7.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_7.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_7.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_7.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_7.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_7.metric_time__day) AS metric_time__extract_doy - , subq_6.ds__day AS ds__day - , subq_6.ds__week AS ds__week - , subq_6.ds__month AS ds__month - , subq_6.ds__quarter AS ds__quarter - , subq_6.ds__year AS ds__year - , subq_6.ds__extract_year AS ds__extract_year - , subq_6.ds__extract_quarter AS ds__extract_quarter - , subq_6.ds__extract_month AS ds__extract_month - , subq_6.ds__extract_day AS ds__extract_day - , subq_6.ds__extract_dow AS ds__extract_dow - , subq_6.ds__extract_doy AS ds__extract_doy - , subq_6.ds_partitioned__day AS ds_partitioned__day - , subq_6.ds_partitioned__week AS ds_partitioned__week - , subq_6.ds_partitioned__month AS ds_partitioned__month - , subq_6.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_6.ds_partitioned__year AS ds_partitioned__year - , subq_6.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_6.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_6.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_6.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_6.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_6.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_6.paid_at__day AS paid_at__day - , subq_6.paid_at__week AS paid_at__week - , subq_6.paid_at__month AS paid_at__month - , subq_6.paid_at__quarter AS paid_at__quarter - , subq_6.paid_at__year AS paid_at__year - , subq_6.paid_at__extract_year AS paid_at__extract_year - , subq_6.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_6.paid_at__extract_month AS paid_at__extract_month - , subq_6.paid_at__extract_day AS paid_at__extract_day - , subq_6.paid_at__extract_dow AS paid_at__extract_dow - , subq_6.paid_at__extract_doy AS paid_at__extract_doy - , subq_6.booking__ds__day AS booking__ds__day - , subq_6.booking__ds__week AS booking__ds__week - , subq_6.booking__ds__month AS booking__ds__month - , subq_6.booking__ds__quarter AS booking__ds__quarter - , subq_6.booking__ds__year AS booking__ds__year - , subq_6.booking__ds__extract_year AS booking__ds__extract_year - , subq_6.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_6.booking__ds__extract_month AS booking__ds__extract_month - , subq_6.booking__ds__extract_day AS booking__ds__extract_day - , subq_6.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_6.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_6.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_6.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_6.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_6.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_6.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_6.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_6.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_6.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_6.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_6.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_6.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_6.booking__paid_at__day AS booking__paid_at__day - , subq_6.booking__paid_at__week AS booking__paid_at__week - , subq_6.booking__paid_at__month AS booking__paid_at__month - , subq_6.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_6.booking__paid_at__year AS booking__paid_at__year - , subq_6.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_6.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_6.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_6.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_6.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_6.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_6.listing AS listing - , subq_6.guest AS guest - , subq_6.host AS host - , subq_6.booking__listing AS booking__listing - , subq_6.booking__guest AS booking__guest - , subq_6.booking__host AS booking__host - , subq_6.is_instant AS is_instant - , subq_6.booking__is_instant AS booking__is_instant - , subq_6.bookings AS bookings - , subq_6.instant_bookings AS instant_bookings - , subq_6.booking_value AS booking_value - , subq_6.max_booking_value AS max_booking_value - , subq_6.min_booking_value AS min_booking_value - , subq_6.bookers AS bookers - , subq_6.average_booking_value AS average_booking_value - , subq_6.referred_bookings AS referred_bookings - , subq_6.median_booking_value AS median_booking_value - , subq_6.booking_value_p99 AS booking_value_p99 - , subq_6.discrete_booking_value_p99 AS discrete_booking_value_p99 - , 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 ( - -- Time Spine - SELECT - subq_8.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_8 - ) subq_7 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ON - subq_7.metric_time__day - INTERVAL 14 day = subq_6.metric_time__day - ) subq_9 - ) subq_10 + ) subq_4 + ) subq_5 + ON + subq_6.metric_time__day - INTERVAL 14 day = subq_5.metric_time__day + ) subq_8 GROUP BY - subq_10.metric_time__extract_dow - ) subq_11 - ) subq_12 + subq_8.metric_time__extract_dow + ) subq_9 + ) subq_10 ON - subq_4.metric_time__extract_dow = subq_12.metric_time__extract_dow + subq_3.metric_time__extract_dow = subq_10.metric_time__extract_dow GROUP BY - COALESCE(subq_4.metric_time__extract_dow, subq_12.metric_time__extract_dow) -) subq_13 + COALESCE(subq_3.metric_time__extract_dow, subq_10.metric_time__extract_dow) +) subq_11 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 9ab2ad55e6..0c44cf6071 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) AS metric_time__extract_dow - , MAX(subq_18.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_15.metric_time__extract_dow, subq_22.metric_time__extract_dow) AS metric_time__extract_dow + , MAX(subq_15.bookings) AS bookings + , MAX(subq_22.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -22,19 +22,19 @@ FROM ( EXTRACT(isodow FROM ds) AS metric_time__extract_dow , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_13 GROUP BY metric_time__extract_dow - ) subq_18 + ) subq_15 FULL OUTER JOIN ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - EXTRACT(isodow FROM subq_22.ds) AS metric_time__extract_dow - , SUM(subq_20.bookings) AS bookings_2_weeks_ago - FROM ***************************.mf_time_spine subq_22 + EXTRACT(isodow FROM subq_19.ds) AS metric_time__extract_dow + , SUM(subq_17.bookings) AS bookings_2_weeks_ago + FROM ***************************.mf_time_spine subq_19 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,14 +42,14 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_20 + ) subq_17 ON - subq_22.ds - INTERVAL 14 day = subq_20.metric_time__day + subq_19.ds - INTERVAL 14 day = subq_17.metric_time__day GROUP BY - EXTRACT(isodow FROM subq_22.ds) - ) subq_26 + EXTRACT(isodow FROM subq_19.ds) + ) subq_22 ON - subq_18.metric_time__extract_dow = subq_26.metric_time__extract_dow + subq_15.metric_time__extract_dow = subq_22.metric_time__extract_dow GROUP BY - COALESCE(subq_18.metric_time__extract_dow, subq_26.metric_time__extract_dow) -) subq_27 + COALESCE(subq_15.metric_time__extract_dow, subq_22.metric_time__extract_dow) +) subq_23 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0.sql index c2505892cd..a077184138 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0.sql @@ -1,1304 +1,831 @@ -- Compute Metrics via Expressions SELECT - subq_12.listing__user__bio_added_ts__minute - , subq_12.bookings + subq_8.listing__user__bio_added_ts__minute + , subq_8.bookings FROM ( -- Aggregate Measures SELECT - subq_11.listing__user__bio_added_ts__minute - , SUM(subq_11.bookings) AS bookings + subq_7.listing__user__bio_added_ts__minute + , SUM(subq_7.bookings) AS bookings FROM ( + -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__user__bio_added_ts__minute'] SELECT - subq_10.listing__user__bio_added_ts__minute - , subq_10.bookings + subq_1.bookings AS bookings FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'ds_partitioned__day', 'listing'] + SELECT + subq_0.ds_partitioned__day + , subq_0.listing + , subq_0.bookings + 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 + ) subq_1 + LEFT OUTER JOIN ( -- Join Standard Outputs + -- Pass Only Elements: ['user__ds_partitioned__day', 'user__bio_added_ts__minute', 'listing'] SELECT - subq_2.ds_partitioned__day AS ds_partitioned__day - , subq_9.user__ds_partitioned__day AS listing__user__ds_partitioned__day - , subq_9.user__bio_added_ts__minute AS listing__user__bio_added_ts__minute - , subq_2.listing AS listing - , subq_2.bookings AS bookings + subq_3.listing AS listing FROM ( - -- Pass Only Elements: ['bookings', 'ds_partitioned__day', 'listing'] + -- Metric Time Dimension 'ds' SELECT - subq_1.ds_partitioned__day - , subq_1.listing - , subq_1.bookings + 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.created_at__day + , subq_2.created_at__week + , subq_2.created_at__month + , subq_2.created_at__quarter + , subq_2.created_at__year + , subq_2.created_at__extract_year + , subq_2.created_at__extract_quarter + , subq_2.created_at__extract_month + , subq_2.created_at__extract_day + , subq_2.created_at__extract_dow + , subq_2.created_at__extract_doy + , subq_2.listing__ds__day + , subq_2.listing__ds__week + , subq_2.listing__ds__month + , subq_2.listing__ds__quarter + , subq_2.listing__ds__year + , subq_2.listing__ds__extract_year + , subq_2.listing__ds__extract_quarter + , subq_2.listing__ds__extract_month + , subq_2.listing__ds__extract_day + , subq_2.listing__ds__extract_dow + , subq_2.listing__ds__extract_doy + , subq_2.listing__created_at__day + , subq_2.listing__created_at__week + , subq_2.listing__created_at__month + , subq_2.listing__created_at__quarter + , subq_2.listing__created_at__year + , subq_2.listing__created_at__extract_year + , subq_2.listing__created_at__extract_quarter + , subq_2.listing__created_at__extract_month + , subq_2.listing__created_at__extract_day + , subq_2.listing__created_at__extract_dow + , subq_2.listing__created_at__extract_doy + , subq_2.ds__day AS metric_time__day + , subq_2.ds__week AS metric_time__week + , subq_2.ds__month AS metric_time__month + , subq_2.ds__quarter AS metric_time__quarter + , subq_2.ds__year AS metric_time__year + , subq_2.ds__extract_year AS metric_time__extract_year + , subq_2.ds__extract_quarter AS metric_time__extract_quarter + , subq_2.ds__extract_month AS metric_time__extract_month + , subq_2.ds__extract_day AS metric_time__extract_day + , subq_2.ds__extract_dow AS metric_time__extract_dow + , subq_2.ds__extract_doy AS metric_time__extract_doy + , subq_2.listing + , subq_2.user + , subq_2.listing__user + , subq_2.country_latest + , subq_2.is_lux_latest + , subq_2.capacity_latest + , subq_2.listing__country_latest + , subq_2.listing__is_lux_latest + , subq_2.listing__capacity_latest + , subq_2.listings + , subq_2.largest_listing + , subq_2.smallest_listing FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 LEFT OUTER JOIN ( - -- Pass Only Elements: ['user__ds_partitioned__day', 'user__bio_added_ts__minute', 'listing'] + -- Metric Time Dimension 'created_at' + -- Pass Only Elements: [ + -- 'home_state', + -- 'user__home_state', + -- 'ds__day', + -- 'ds__week', + -- 'ds__month', + -- 'ds__quarter', + -- 'ds__year', + -- 'ds__extract_year', + -- 'ds__extract_quarter', + -- 'ds__extract_month', + -- 'ds__extract_day', + -- 'ds__extract_dow', + -- 'ds__extract_doy', + -- 'created_at__day', + -- 'created_at__week', + -- 'created_at__month', + -- 'created_at__quarter', + -- 'created_at__year', + -- 'created_at__extract_year', + -- 'created_at__extract_quarter', + -- 'created_at__extract_month', + -- 'created_at__extract_day', + -- 'created_at__extract_dow', + -- 'created_at__extract_doy', + -- 'ds_partitioned__day', + -- 'ds_partitioned__week', + -- 'ds_partitioned__month', + -- 'ds_partitioned__quarter', + -- 'ds_partitioned__year', + -- 'ds_partitioned__extract_year', + -- 'ds_partitioned__extract_quarter', + -- 'ds_partitioned__extract_month', + -- 'ds_partitioned__extract_day', + -- 'ds_partitioned__extract_dow', + -- 'ds_partitioned__extract_doy', + -- 'last_profile_edit_ts__millisecond', + -- 'last_profile_edit_ts__second', + -- 'last_profile_edit_ts__minute', + -- 'last_profile_edit_ts__hour', + -- 'last_profile_edit_ts__day', + -- 'last_profile_edit_ts__week', + -- 'last_profile_edit_ts__month', + -- 'last_profile_edit_ts__quarter', + -- 'last_profile_edit_ts__year', + -- 'last_profile_edit_ts__extract_year', + -- 'last_profile_edit_ts__extract_quarter', + -- 'last_profile_edit_ts__extract_month', + -- 'last_profile_edit_ts__extract_day', + -- 'last_profile_edit_ts__extract_dow', + -- 'last_profile_edit_ts__extract_doy', + -- 'bio_added_ts__second', + -- 'bio_added_ts__minute', + -- 'bio_added_ts__hour', + -- 'bio_added_ts__day', + -- 'bio_added_ts__week', + -- 'bio_added_ts__month', + -- 'bio_added_ts__quarter', + -- 'bio_added_ts__year', + -- 'bio_added_ts__extract_year', + -- 'bio_added_ts__extract_quarter', + -- 'bio_added_ts__extract_month', + -- 'bio_added_ts__extract_day', + -- 'bio_added_ts__extract_dow', + -- 'bio_added_ts__extract_doy', + -- 'last_login_ts__minute', + -- 'last_login_ts__hour', + -- 'last_login_ts__day', + -- 'last_login_ts__week', + -- 'last_login_ts__month', + -- 'last_login_ts__quarter', + -- 'last_login_ts__year', + -- 'last_login_ts__extract_year', + -- 'last_login_ts__extract_quarter', + -- 'last_login_ts__extract_month', + -- 'last_login_ts__extract_day', + -- 'last_login_ts__extract_dow', + -- 'last_login_ts__extract_doy', + -- 'archived_at__hour', + -- 'archived_at__day', + -- 'archived_at__week', + -- 'archived_at__month', + -- 'archived_at__quarter', + -- 'archived_at__year', + -- 'archived_at__extract_year', + -- 'archived_at__extract_quarter', + -- 'archived_at__extract_month', + -- 'archived_at__extract_day', + -- 'archived_at__extract_dow', + -- 'archived_at__extract_doy', + -- 'user__ds__day', + -- 'user__ds__week', + -- 'user__ds__month', + -- 'user__ds__quarter', + -- 'user__ds__year', + -- 'user__ds__extract_year', + -- 'user__ds__extract_quarter', + -- 'user__ds__extract_month', + -- 'user__ds__extract_day', + -- 'user__ds__extract_dow', + -- 'user__ds__extract_doy', + -- 'user__created_at__day', + -- 'user__created_at__week', + -- 'user__created_at__month', + -- 'user__created_at__quarter', + -- 'user__created_at__year', + -- 'user__created_at__extract_year', + -- 'user__created_at__extract_quarter', + -- 'user__created_at__extract_month', + -- 'user__created_at__extract_day', + -- 'user__created_at__extract_dow', + -- 'user__created_at__extract_doy', + -- 'user__ds_partitioned__day', + -- 'user__ds_partitioned__week', + -- 'user__ds_partitioned__month', + -- 'user__ds_partitioned__quarter', + -- 'user__ds_partitioned__year', + -- 'user__ds_partitioned__extract_year', + -- 'user__ds_partitioned__extract_quarter', + -- 'user__ds_partitioned__extract_month', + -- 'user__ds_partitioned__extract_day', + -- 'user__ds_partitioned__extract_dow', + -- 'user__ds_partitioned__extract_doy', + -- 'user__last_profile_edit_ts__millisecond', + -- 'user__last_profile_edit_ts__second', + -- 'user__last_profile_edit_ts__minute', + -- 'user__last_profile_edit_ts__hour', + -- 'user__last_profile_edit_ts__day', + -- 'user__last_profile_edit_ts__week', + -- 'user__last_profile_edit_ts__month', + -- 'user__last_profile_edit_ts__quarter', + -- 'user__last_profile_edit_ts__year', + -- 'user__last_profile_edit_ts__extract_year', + -- 'user__last_profile_edit_ts__extract_quarter', + -- 'user__last_profile_edit_ts__extract_month', + -- 'user__last_profile_edit_ts__extract_day', + -- 'user__last_profile_edit_ts__extract_dow', + -- 'user__last_profile_edit_ts__extract_doy', + -- 'user__bio_added_ts__second', + -- 'user__bio_added_ts__minute', + -- 'user__bio_added_ts__hour', + -- 'user__bio_added_ts__day', + -- 'user__bio_added_ts__week', + -- 'user__bio_added_ts__month', + -- 'user__bio_added_ts__quarter', + -- 'user__bio_added_ts__year', + -- 'user__bio_added_ts__extract_year', + -- 'user__bio_added_ts__extract_quarter', + -- 'user__bio_added_ts__extract_month', + -- 'user__bio_added_ts__extract_day', + -- 'user__bio_added_ts__extract_dow', + -- 'user__bio_added_ts__extract_doy', + -- 'user__last_login_ts__minute', + -- 'user__last_login_ts__hour', + -- 'user__last_login_ts__day', + -- 'user__last_login_ts__week', + -- 'user__last_login_ts__month', + -- 'user__last_login_ts__quarter', + -- 'user__last_login_ts__year', + -- 'user__last_login_ts__extract_year', + -- 'user__last_login_ts__extract_quarter', + -- 'user__last_login_ts__extract_month', + -- 'user__last_login_ts__extract_day', + -- 'user__last_login_ts__extract_dow', + -- 'user__last_login_ts__extract_doy', + -- 'user__archived_at__hour', + -- 'user__archived_at__day', + -- 'user__archived_at__week', + -- 'user__archived_at__month', + -- 'user__archived_at__quarter', + -- 'user__archived_at__year', + -- 'user__archived_at__extract_year', + -- 'user__archived_at__extract_quarter', + -- 'user__archived_at__extract_month', + -- 'user__archived_at__extract_day', + -- 'user__archived_at__extract_dow', + -- 'user__archived_at__extract_doy', + -- 'metric_time__day', + -- 'metric_time__week', + -- 'metric_time__month', + -- 'metric_time__quarter', + -- 'metric_time__year', + -- 'metric_time__extract_year', + -- 'metric_time__extract_quarter', + -- 'metric_time__extract_month', + -- 'metric_time__extract_day', + -- 'metric_time__extract_dow', + -- 'metric_time__extract_doy', + -- 'user', + -- ] SELECT - subq_8.user__ds_partitioned__day - , subq_8.user__bio_added_ts__minute - , subq_8.listing + 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.created_at__day + , subq_4.created_at__week + , subq_4.created_at__month + , subq_4.created_at__quarter + , subq_4.created_at__year + , subq_4.created_at__extract_year + , subq_4.created_at__extract_quarter + , subq_4.created_at__extract_month + , subq_4.created_at__extract_day + , subq_4.created_at__extract_dow + , subq_4.created_at__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.last_profile_edit_ts__millisecond + , subq_4.last_profile_edit_ts__second + , subq_4.last_profile_edit_ts__minute + , subq_4.last_profile_edit_ts__hour + , subq_4.last_profile_edit_ts__day + , subq_4.last_profile_edit_ts__week + , subq_4.last_profile_edit_ts__month + , subq_4.last_profile_edit_ts__quarter + , subq_4.last_profile_edit_ts__year + , subq_4.last_profile_edit_ts__extract_year + , subq_4.last_profile_edit_ts__extract_quarter + , subq_4.last_profile_edit_ts__extract_month + , subq_4.last_profile_edit_ts__extract_day + , subq_4.last_profile_edit_ts__extract_dow + , subq_4.last_profile_edit_ts__extract_doy + , subq_4.bio_added_ts__second + , subq_4.bio_added_ts__minute + , subq_4.bio_added_ts__hour + , subq_4.bio_added_ts__day + , subq_4.bio_added_ts__week + , subq_4.bio_added_ts__month + , subq_4.bio_added_ts__quarter + , subq_4.bio_added_ts__year + , subq_4.bio_added_ts__extract_year + , subq_4.bio_added_ts__extract_quarter + , subq_4.bio_added_ts__extract_month + , subq_4.bio_added_ts__extract_day + , subq_4.bio_added_ts__extract_dow + , subq_4.bio_added_ts__extract_doy + , subq_4.last_login_ts__minute + , subq_4.last_login_ts__hour + , subq_4.last_login_ts__day + , subq_4.last_login_ts__week + , subq_4.last_login_ts__month + , subq_4.last_login_ts__quarter + , subq_4.last_login_ts__year + , subq_4.last_login_ts__extract_year + , subq_4.last_login_ts__extract_quarter + , subq_4.last_login_ts__extract_month + , subq_4.last_login_ts__extract_day + , subq_4.last_login_ts__extract_dow + , subq_4.last_login_ts__extract_doy + , subq_4.archived_at__hour + , subq_4.archived_at__day + , subq_4.archived_at__week + , subq_4.archived_at__month + , subq_4.archived_at__quarter + , subq_4.archived_at__year + , subq_4.archived_at__extract_year + , subq_4.archived_at__extract_quarter + , subq_4.archived_at__extract_month + , subq_4.archived_at__extract_day + , subq_4.archived_at__extract_dow + , subq_4.archived_at__extract_doy + , subq_4.user__ds__day + , subq_4.user__ds__week + , subq_4.user__ds__month + , subq_4.user__ds__quarter + , subq_4.user__ds__year + , subq_4.user__ds__extract_year + , subq_4.user__ds__extract_quarter + , subq_4.user__ds__extract_month + , subq_4.user__ds__extract_day + , subq_4.user__ds__extract_dow + , subq_4.user__ds__extract_doy + , subq_4.user__created_at__day + , subq_4.user__created_at__week + , subq_4.user__created_at__month + , subq_4.user__created_at__quarter + , subq_4.user__created_at__year + , subq_4.user__created_at__extract_year + , subq_4.user__created_at__extract_quarter + , subq_4.user__created_at__extract_month + , subq_4.user__created_at__extract_day + , subq_4.user__created_at__extract_dow + , subq_4.user__created_at__extract_doy + , subq_4.user__ds_partitioned__day + , subq_4.user__ds_partitioned__week + , subq_4.user__ds_partitioned__month + , subq_4.user__ds_partitioned__quarter + , subq_4.user__ds_partitioned__year + , subq_4.user__ds_partitioned__extract_year + , subq_4.user__ds_partitioned__extract_quarter + , subq_4.user__ds_partitioned__extract_month + , subq_4.user__ds_partitioned__extract_day + , subq_4.user__ds_partitioned__extract_dow + , subq_4.user__ds_partitioned__extract_doy + , subq_4.user__last_profile_edit_ts__millisecond + , subq_4.user__last_profile_edit_ts__second + , subq_4.user__last_profile_edit_ts__minute + , subq_4.user__last_profile_edit_ts__hour + , subq_4.user__last_profile_edit_ts__day + , subq_4.user__last_profile_edit_ts__week + , subq_4.user__last_profile_edit_ts__month + , subq_4.user__last_profile_edit_ts__quarter + , subq_4.user__last_profile_edit_ts__year + , subq_4.user__last_profile_edit_ts__extract_year + , subq_4.user__last_profile_edit_ts__extract_quarter + , subq_4.user__last_profile_edit_ts__extract_month + , subq_4.user__last_profile_edit_ts__extract_day + , subq_4.user__last_profile_edit_ts__extract_dow + , subq_4.user__last_profile_edit_ts__extract_doy + , subq_4.user__bio_added_ts__second + , subq_4.user__bio_added_ts__minute + , subq_4.user__bio_added_ts__hour + , subq_4.user__bio_added_ts__day + , subq_4.user__bio_added_ts__week + , subq_4.user__bio_added_ts__month + , subq_4.user__bio_added_ts__quarter + , subq_4.user__bio_added_ts__year + , subq_4.user__bio_added_ts__extract_year + , subq_4.user__bio_added_ts__extract_quarter + , subq_4.user__bio_added_ts__extract_month + , subq_4.user__bio_added_ts__extract_day + , subq_4.user__bio_added_ts__extract_dow + , subq_4.user__bio_added_ts__extract_doy + , subq_4.user__last_login_ts__minute + , subq_4.user__last_login_ts__hour + , subq_4.user__last_login_ts__day + , subq_4.user__last_login_ts__week + , subq_4.user__last_login_ts__month + , subq_4.user__last_login_ts__quarter + , subq_4.user__last_login_ts__year + , subq_4.user__last_login_ts__extract_year + , subq_4.user__last_login_ts__extract_quarter + , subq_4.user__last_login_ts__extract_month + , subq_4.user__last_login_ts__extract_day + , subq_4.user__last_login_ts__extract_dow + , subq_4.user__last_login_ts__extract_doy + , subq_4.user__archived_at__hour + , subq_4.user__archived_at__day + , subq_4.user__archived_at__week + , subq_4.user__archived_at__month + , subq_4.user__archived_at__quarter + , subq_4.user__archived_at__year + , subq_4.user__archived_at__extract_year + , subq_4.user__archived_at__extract_quarter + , subq_4.user__archived_at__extract_month + , subq_4.user__archived_at__extract_day + , subq_4.user__archived_at__extract_dow + , subq_4.user__archived_at__extract_doy + , subq_4.created_at__day AS metric_time__day + , subq_4.created_at__week AS metric_time__week + , subq_4.created_at__month AS metric_time__month + , subq_4.created_at__quarter AS metric_time__quarter + , subq_4.created_at__year AS metric_time__year + , subq_4.created_at__extract_year AS metric_time__extract_year + , subq_4.created_at__extract_quarter AS metric_time__extract_quarter + , subq_4.created_at__extract_month AS metric_time__extract_month + , subq_4.created_at__extract_day AS metric_time__extract_day + , subq_4.created_at__extract_dow AS metric_time__extract_dow + , subq_4.created_at__extract_doy AS metric_time__extract_doy + , subq_4.user + , subq_4.home_state + , subq_4.user__home_state FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_4.ds__day AS ds__day - , subq_4.ds__week AS ds__week - , subq_4.ds__month AS ds__month - , subq_4.ds__quarter AS ds__quarter - , subq_4.ds__year AS ds__year - , subq_4.ds__extract_year AS ds__extract_year - , subq_4.ds__extract_quarter AS ds__extract_quarter - , subq_4.ds__extract_month AS ds__extract_month - , subq_4.ds__extract_day AS ds__extract_day - , subq_4.ds__extract_dow AS ds__extract_dow - , subq_4.ds__extract_doy AS ds__extract_doy - , subq_4.created_at__day AS created_at__day - , subq_4.created_at__week AS created_at__week - , subq_4.created_at__month AS created_at__month - , subq_4.created_at__quarter AS created_at__quarter - , subq_4.created_at__year AS created_at__year - , subq_4.created_at__extract_year AS created_at__extract_year - , subq_4.created_at__extract_quarter AS created_at__extract_quarter - , subq_4.created_at__extract_month AS created_at__extract_month - , subq_4.created_at__extract_day AS created_at__extract_day - , subq_4.created_at__extract_dow AS created_at__extract_dow - , subq_4.created_at__extract_doy AS created_at__extract_doy - , subq_4.listing__ds__day AS listing__ds__day - , subq_4.listing__ds__week AS listing__ds__week - , subq_4.listing__ds__month AS listing__ds__month - , subq_4.listing__ds__quarter AS listing__ds__quarter - , subq_4.listing__ds__year AS listing__ds__year - , subq_4.listing__ds__extract_year AS listing__ds__extract_year - , subq_4.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_4.listing__ds__extract_month AS listing__ds__extract_month - , subq_4.listing__ds__extract_day AS listing__ds__extract_day - , subq_4.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_4.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_4.listing__created_at__day AS listing__created_at__day - , subq_4.listing__created_at__week AS listing__created_at__week - , subq_4.listing__created_at__month AS listing__created_at__month - , subq_4.listing__created_at__quarter AS listing__created_at__quarter - , subq_4.listing__created_at__year AS listing__created_at__year - , subq_4.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_4.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_4.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_4.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_4.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_4.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_4.metric_time__day AS metric_time__day - , subq_4.metric_time__week AS metric_time__week - , subq_4.metric_time__month AS metric_time__month - , subq_4.metric_time__quarter AS metric_time__quarter - , subq_4.metric_time__year AS metric_time__year - , subq_4.metric_time__extract_year AS metric_time__extract_year - , subq_4.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_4.metric_time__extract_month AS metric_time__extract_month - , 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_7.ds__day AS user__ds__day - , subq_7.ds__week AS user__ds__week - , subq_7.ds__month AS user__ds__month - , subq_7.ds__quarter AS user__ds__quarter - , subq_7.ds__year AS user__ds__year - , subq_7.ds__extract_year AS user__ds__extract_year - , subq_7.ds__extract_quarter AS user__ds__extract_quarter - , subq_7.ds__extract_month AS user__ds__extract_month - , subq_7.ds__extract_day AS user__ds__extract_day - , subq_7.ds__extract_dow AS user__ds__extract_dow - , subq_7.ds__extract_doy AS user__ds__extract_doy - , subq_7.created_at__day AS user__created_at__day - , subq_7.created_at__week AS user__created_at__week - , subq_7.created_at__month AS user__created_at__month - , subq_7.created_at__quarter AS user__created_at__quarter - , subq_7.created_at__year AS user__created_at__year - , subq_7.created_at__extract_year AS user__created_at__extract_year - , subq_7.created_at__extract_quarter AS user__created_at__extract_quarter - , subq_7.created_at__extract_month AS user__created_at__extract_month - , subq_7.created_at__extract_day AS user__created_at__extract_day - , subq_7.created_at__extract_dow AS user__created_at__extract_dow - , subq_7.created_at__extract_doy AS user__created_at__extract_doy - , subq_7.ds_partitioned__day AS user__ds_partitioned__day - , subq_7.ds_partitioned__week AS user__ds_partitioned__week - , subq_7.ds_partitioned__month AS user__ds_partitioned__month - , subq_7.ds_partitioned__quarter AS user__ds_partitioned__quarter - , subq_7.ds_partitioned__year AS user__ds_partitioned__year - , subq_7.ds_partitioned__extract_year AS user__ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter AS user__ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month AS user__ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day AS user__ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow AS user__ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy AS user__ds_partitioned__extract_doy - , subq_7.last_profile_edit_ts__millisecond AS user__last_profile_edit_ts__millisecond - , subq_7.last_profile_edit_ts__second AS user__last_profile_edit_ts__second - , subq_7.last_profile_edit_ts__minute AS user__last_profile_edit_ts__minute - , subq_7.last_profile_edit_ts__hour AS user__last_profile_edit_ts__hour - , subq_7.last_profile_edit_ts__day AS user__last_profile_edit_ts__day - , subq_7.last_profile_edit_ts__week AS user__last_profile_edit_ts__week - , subq_7.last_profile_edit_ts__month AS user__last_profile_edit_ts__month - , subq_7.last_profile_edit_ts__quarter AS user__last_profile_edit_ts__quarter - , subq_7.last_profile_edit_ts__year AS user__last_profile_edit_ts__year - , subq_7.last_profile_edit_ts__extract_year AS user__last_profile_edit_ts__extract_year - , subq_7.last_profile_edit_ts__extract_quarter AS user__last_profile_edit_ts__extract_quarter - , subq_7.last_profile_edit_ts__extract_month AS user__last_profile_edit_ts__extract_month - , subq_7.last_profile_edit_ts__extract_day AS user__last_profile_edit_ts__extract_day - , subq_7.last_profile_edit_ts__extract_dow AS user__last_profile_edit_ts__extract_dow - , subq_7.last_profile_edit_ts__extract_doy AS user__last_profile_edit_ts__extract_doy - , subq_7.bio_added_ts__second AS user__bio_added_ts__second - , subq_7.bio_added_ts__minute AS user__bio_added_ts__minute - , subq_7.bio_added_ts__hour AS user__bio_added_ts__hour - , subq_7.bio_added_ts__day AS user__bio_added_ts__day - , subq_7.bio_added_ts__week AS user__bio_added_ts__week - , subq_7.bio_added_ts__month AS user__bio_added_ts__month - , subq_7.bio_added_ts__quarter AS user__bio_added_ts__quarter - , subq_7.bio_added_ts__year AS user__bio_added_ts__year - , subq_7.bio_added_ts__extract_year AS user__bio_added_ts__extract_year - , subq_7.bio_added_ts__extract_quarter AS user__bio_added_ts__extract_quarter - , subq_7.bio_added_ts__extract_month AS user__bio_added_ts__extract_month - , subq_7.bio_added_ts__extract_day AS user__bio_added_ts__extract_day - , subq_7.bio_added_ts__extract_dow AS user__bio_added_ts__extract_dow - , subq_7.bio_added_ts__extract_doy AS user__bio_added_ts__extract_doy - , subq_7.last_login_ts__minute AS user__last_login_ts__minute - , subq_7.last_login_ts__hour AS user__last_login_ts__hour - , subq_7.last_login_ts__day AS user__last_login_ts__day - , subq_7.last_login_ts__week AS user__last_login_ts__week - , subq_7.last_login_ts__month AS user__last_login_ts__month - , subq_7.last_login_ts__quarter AS user__last_login_ts__quarter - , subq_7.last_login_ts__year AS user__last_login_ts__year - , subq_7.last_login_ts__extract_year AS user__last_login_ts__extract_year - , subq_7.last_login_ts__extract_quarter AS user__last_login_ts__extract_quarter - , subq_7.last_login_ts__extract_month AS user__last_login_ts__extract_month - , subq_7.last_login_ts__extract_day AS user__last_login_ts__extract_day - , subq_7.last_login_ts__extract_dow AS user__last_login_ts__extract_dow - , subq_7.last_login_ts__extract_doy AS user__last_login_ts__extract_doy - , subq_7.archived_at__hour AS user__archived_at__hour - , subq_7.archived_at__day AS user__archived_at__day - , subq_7.archived_at__week AS user__archived_at__week - , subq_7.archived_at__month AS user__archived_at__month - , subq_7.archived_at__quarter AS user__archived_at__quarter - , subq_7.archived_at__year AS user__archived_at__year - , subq_7.archived_at__extract_year AS user__archived_at__extract_year - , subq_7.archived_at__extract_quarter AS user__archived_at__extract_quarter - , subq_7.archived_at__extract_month AS user__archived_at__extract_month - , subq_7.archived_at__extract_day AS user__archived_at__extract_day - , subq_7.archived_at__extract_dow AS user__archived_at__extract_dow - , subq_7.archived_at__extract_doy AS user__archived_at__extract_doy - , subq_7.metric_time__day AS user__metric_time__day - , subq_7.metric_time__week AS user__metric_time__week - , subq_7.metric_time__month AS user__metric_time__month - , subq_7.metric_time__quarter AS user__metric_time__quarter - , subq_7.metric_time__year AS user__metric_time__year - , subq_7.metric_time__extract_year AS user__metric_time__extract_year - , subq_7.metric_time__extract_quarter AS user__metric_time__extract_quarter - , subq_7.metric_time__extract_month AS user__metric_time__extract_month - , subq_7.metric_time__extract_day AS user__metric_time__extract_day - , subq_7.metric_time__extract_dow AS user__metric_time__extract_dow - , subq_7.metric_time__extract_doy AS user__metric_time__extract_doy - , subq_4.listing AS listing - , subq_4.user AS user - , subq_4.listing__user AS listing__user - , subq_4.country_latest AS country_latest - , subq_4.is_lux_latest AS is_lux_latest - , subq_4.capacity_latest AS capacity_latest - , subq_4.listing__country_latest AS listing__country_latest - , subq_4.listing__is_lux_latest AS listing__is_lux_latest - , subq_4.listing__capacity_latest AS listing__capacity_latest - , subq_7.home_state AS user__home_state - , subq_4.listings AS listings - , subq_4.largest_listing AS largest_listing - , subq_4.smallest_listing AS smallest_listing - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - LEFT OUTER JOIN ( - -- Pass Only Elements: [ - -- 'home_state', - -- 'user__home_state', - -- 'ds__day', - -- 'ds__week', - -- 'ds__month', - -- 'ds__quarter', - -- 'ds__year', - -- 'ds__extract_year', - -- 'ds__extract_quarter', - -- 'ds__extract_month', - -- 'ds__extract_day', - -- 'ds__extract_dow', - -- 'ds__extract_doy', - -- 'created_at__day', - -- 'created_at__week', - -- 'created_at__month', - -- 'created_at__quarter', - -- 'created_at__year', - -- 'created_at__extract_year', - -- 'created_at__extract_quarter', - -- 'created_at__extract_month', - -- 'created_at__extract_day', - -- 'created_at__extract_dow', - -- 'created_at__extract_doy', - -- 'ds_partitioned__day', - -- 'ds_partitioned__week', - -- 'ds_partitioned__month', - -- 'ds_partitioned__quarter', - -- 'ds_partitioned__year', - -- 'ds_partitioned__extract_year', - -- 'ds_partitioned__extract_quarter', - -- 'ds_partitioned__extract_month', - -- 'ds_partitioned__extract_day', - -- 'ds_partitioned__extract_dow', - -- 'ds_partitioned__extract_doy', - -- 'last_profile_edit_ts__millisecond', - -- 'last_profile_edit_ts__second', - -- 'last_profile_edit_ts__minute', - -- 'last_profile_edit_ts__hour', - -- 'last_profile_edit_ts__day', - -- 'last_profile_edit_ts__week', - -- 'last_profile_edit_ts__month', - -- 'last_profile_edit_ts__quarter', - -- 'last_profile_edit_ts__year', - -- 'last_profile_edit_ts__extract_year', - -- 'last_profile_edit_ts__extract_quarter', - -- 'last_profile_edit_ts__extract_month', - -- 'last_profile_edit_ts__extract_day', - -- 'last_profile_edit_ts__extract_dow', - -- 'last_profile_edit_ts__extract_doy', - -- 'bio_added_ts__second', - -- 'bio_added_ts__minute', - -- 'bio_added_ts__hour', - -- 'bio_added_ts__day', - -- 'bio_added_ts__week', - -- 'bio_added_ts__month', - -- 'bio_added_ts__quarter', - -- 'bio_added_ts__year', - -- 'bio_added_ts__extract_year', - -- 'bio_added_ts__extract_quarter', - -- 'bio_added_ts__extract_month', - -- 'bio_added_ts__extract_day', - -- 'bio_added_ts__extract_dow', - -- 'bio_added_ts__extract_doy', - -- 'last_login_ts__minute', - -- 'last_login_ts__hour', - -- 'last_login_ts__day', - -- 'last_login_ts__week', - -- 'last_login_ts__month', - -- 'last_login_ts__quarter', - -- 'last_login_ts__year', - -- 'last_login_ts__extract_year', - -- 'last_login_ts__extract_quarter', - -- 'last_login_ts__extract_month', - -- 'last_login_ts__extract_day', - -- 'last_login_ts__extract_dow', - -- 'last_login_ts__extract_doy', - -- 'archived_at__hour', - -- 'archived_at__day', - -- 'archived_at__week', - -- 'archived_at__month', - -- 'archived_at__quarter', - -- 'archived_at__year', - -- 'archived_at__extract_year', - -- 'archived_at__extract_quarter', - -- 'archived_at__extract_month', - -- 'archived_at__extract_day', - -- 'archived_at__extract_dow', - -- 'archived_at__extract_doy', - -- 'user__ds__day', - -- 'user__ds__week', - -- 'user__ds__month', - -- 'user__ds__quarter', - -- 'user__ds__year', - -- 'user__ds__extract_year', - -- 'user__ds__extract_quarter', - -- 'user__ds__extract_month', - -- 'user__ds__extract_day', - -- 'user__ds__extract_dow', - -- 'user__ds__extract_doy', - -- 'user__created_at__day', - -- 'user__created_at__week', - -- 'user__created_at__month', - -- 'user__created_at__quarter', - -- 'user__created_at__year', - -- 'user__created_at__extract_year', - -- 'user__created_at__extract_quarter', - -- 'user__created_at__extract_month', - -- 'user__created_at__extract_day', - -- 'user__created_at__extract_dow', - -- 'user__created_at__extract_doy', - -- 'user__ds_partitioned__day', - -- 'user__ds_partitioned__week', - -- 'user__ds_partitioned__month', - -- 'user__ds_partitioned__quarter', - -- 'user__ds_partitioned__year', - -- 'user__ds_partitioned__extract_year', - -- 'user__ds_partitioned__extract_quarter', - -- 'user__ds_partitioned__extract_month', - -- 'user__ds_partitioned__extract_day', - -- 'user__ds_partitioned__extract_dow', - -- 'user__ds_partitioned__extract_doy', - -- 'user__last_profile_edit_ts__millisecond', - -- 'user__last_profile_edit_ts__second', - -- 'user__last_profile_edit_ts__minute', - -- 'user__last_profile_edit_ts__hour', - -- 'user__last_profile_edit_ts__day', - -- 'user__last_profile_edit_ts__week', - -- 'user__last_profile_edit_ts__month', - -- 'user__last_profile_edit_ts__quarter', - -- 'user__last_profile_edit_ts__year', - -- 'user__last_profile_edit_ts__extract_year', - -- 'user__last_profile_edit_ts__extract_quarter', - -- 'user__last_profile_edit_ts__extract_month', - -- 'user__last_profile_edit_ts__extract_day', - -- 'user__last_profile_edit_ts__extract_dow', - -- 'user__last_profile_edit_ts__extract_doy', - -- 'user__bio_added_ts__second', - -- 'user__bio_added_ts__minute', - -- 'user__bio_added_ts__hour', - -- 'user__bio_added_ts__day', - -- 'user__bio_added_ts__week', - -- 'user__bio_added_ts__month', - -- 'user__bio_added_ts__quarter', - -- 'user__bio_added_ts__year', - -- 'user__bio_added_ts__extract_year', - -- 'user__bio_added_ts__extract_quarter', - -- 'user__bio_added_ts__extract_month', - -- 'user__bio_added_ts__extract_day', - -- 'user__bio_added_ts__extract_dow', - -- 'user__bio_added_ts__extract_doy', - -- 'user__last_login_ts__minute', - -- 'user__last_login_ts__hour', - -- 'user__last_login_ts__day', - -- 'user__last_login_ts__week', - -- 'user__last_login_ts__month', - -- 'user__last_login_ts__quarter', - -- 'user__last_login_ts__year', - -- 'user__last_login_ts__extract_year', - -- 'user__last_login_ts__extract_quarter', - -- 'user__last_login_ts__extract_month', - -- 'user__last_login_ts__extract_day', - -- 'user__last_login_ts__extract_dow', - -- 'user__last_login_ts__extract_doy', - -- 'user__archived_at__hour', - -- 'user__archived_at__day', - -- 'user__archived_at__week', - -- 'user__archived_at__month', - -- 'user__archived_at__quarter', - -- 'user__archived_at__year', - -- 'user__archived_at__extract_year', - -- 'user__archived_at__extract_quarter', - -- 'user__archived_at__extract_month', - -- 'user__archived_at__extract_day', - -- 'user__archived_at__extract_dow', - -- 'user__archived_at__extract_doy', - -- 'metric_time__day', - -- 'metric_time__week', - -- 'metric_time__month', - -- 'metric_time__quarter', - -- 'metric_time__year', - -- 'metric_time__extract_year', - -- 'metric_time__extract_quarter', - -- 'metric_time__extract_month', - -- 'metric_time__extract_day', - -- 'metric_time__extract_dow', - -- 'metric_time__extract_doy', - -- 'user', - -- ] - SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.created_at__day - , subq_6.created_at__week - , subq_6.created_at__month - , subq_6.created_at__quarter - , subq_6.created_at__year - , subq_6.created_at__extract_year - , subq_6.created_at__extract_quarter - , subq_6.created_at__extract_month - , subq_6.created_at__extract_day - , subq_6.created_at__extract_dow - , subq_6.created_at__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.last_profile_edit_ts__millisecond - , subq_6.last_profile_edit_ts__second - , subq_6.last_profile_edit_ts__minute - , subq_6.last_profile_edit_ts__hour - , subq_6.last_profile_edit_ts__day - , subq_6.last_profile_edit_ts__week - , subq_6.last_profile_edit_ts__month - , subq_6.last_profile_edit_ts__quarter - , subq_6.last_profile_edit_ts__year - , subq_6.last_profile_edit_ts__extract_year - , subq_6.last_profile_edit_ts__extract_quarter - , subq_6.last_profile_edit_ts__extract_month - , subq_6.last_profile_edit_ts__extract_day - , subq_6.last_profile_edit_ts__extract_dow - , subq_6.last_profile_edit_ts__extract_doy - , subq_6.bio_added_ts__second - , subq_6.bio_added_ts__minute - , subq_6.bio_added_ts__hour - , subq_6.bio_added_ts__day - , subq_6.bio_added_ts__week - , subq_6.bio_added_ts__month - , subq_6.bio_added_ts__quarter - , subq_6.bio_added_ts__year - , subq_6.bio_added_ts__extract_year - , subq_6.bio_added_ts__extract_quarter - , subq_6.bio_added_ts__extract_month - , subq_6.bio_added_ts__extract_day - , subq_6.bio_added_ts__extract_dow - , subq_6.bio_added_ts__extract_doy - , subq_6.last_login_ts__minute - , subq_6.last_login_ts__hour - , subq_6.last_login_ts__day - , subq_6.last_login_ts__week - , subq_6.last_login_ts__month - , subq_6.last_login_ts__quarter - , subq_6.last_login_ts__year - , subq_6.last_login_ts__extract_year - , subq_6.last_login_ts__extract_quarter - , subq_6.last_login_ts__extract_month - , subq_6.last_login_ts__extract_day - , subq_6.last_login_ts__extract_dow - , subq_6.last_login_ts__extract_doy - , subq_6.archived_at__hour - , subq_6.archived_at__day - , subq_6.archived_at__week - , subq_6.archived_at__month - , subq_6.archived_at__quarter - , subq_6.archived_at__year - , subq_6.archived_at__extract_year - , subq_6.archived_at__extract_quarter - , subq_6.archived_at__extract_month - , subq_6.archived_at__extract_day - , subq_6.archived_at__extract_dow - , subq_6.archived_at__extract_doy - , subq_6.user__ds__day - , subq_6.user__ds__week - , subq_6.user__ds__month - , subq_6.user__ds__quarter - , subq_6.user__ds__year - , subq_6.user__ds__extract_year - , subq_6.user__ds__extract_quarter - , subq_6.user__ds__extract_month - , subq_6.user__ds__extract_day - , subq_6.user__ds__extract_dow - , subq_6.user__ds__extract_doy - , subq_6.user__created_at__day - , subq_6.user__created_at__week - , subq_6.user__created_at__month - , subq_6.user__created_at__quarter - , subq_6.user__created_at__year - , subq_6.user__created_at__extract_year - , subq_6.user__created_at__extract_quarter - , subq_6.user__created_at__extract_month - , subq_6.user__created_at__extract_day - , subq_6.user__created_at__extract_dow - , subq_6.user__created_at__extract_doy - , subq_6.user__ds_partitioned__day - , subq_6.user__ds_partitioned__week - , subq_6.user__ds_partitioned__month - , subq_6.user__ds_partitioned__quarter - , subq_6.user__ds_partitioned__year - , subq_6.user__ds_partitioned__extract_year - , subq_6.user__ds_partitioned__extract_quarter - , subq_6.user__ds_partitioned__extract_month - , subq_6.user__ds_partitioned__extract_day - , subq_6.user__ds_partitioned__extract_dow - , subq_6.user__ds_partitioned__extract_doy - , subq_6.user__last_profile_edit_ts__millisecond - , subq_6.user__last_profile_edit_ts__second - , subq_6.user__last_profile_edit_ts__minute - , subq_6.user__last_profile_edit_ts__hour - , subq_6.user__last_profile_edit_ts__day - , subq_6.user__last_profile_edit_ts__week - , subq_6.user__last_profile_edit_ts__month - , subq_6.user__last_profile_edit_ts__quarter - , subq_6.user__last_profile_edit_ts__year - , subq_6.user__last_profile_edit_ts__extract_year - , subq_6.user__last_profile_edit_ts__extract_quarter - , subq_6.user__last_profile_edit_ts__extract_month - , subq_6.user__last_profile_edit_ts__extract_day - , subq_6.user__last_profile_edit_ts__extract_dow - , subq_6.user__last_profile_edit_ts__extract_doy - , subq_6.user__bio_added_ts__second - , subq_6.user__bio_added_ts__minute - , subq_6.user__bio_added_ts__hour - , subq_6.user__bio_added_ts__day - , subq_6.user__bio_added_ts__week - , subq_6.user__bio_added_ts__month - , subq_6.user__bio_added_ts__quarter - , subq_6.user__bio_added_ts__year - , subq_6.user__bio_added_ts__extract_year - , subq_6.user__bio_added_ts__extract_quarter - , subq_6.user__bio_added_ts__extract_month - , subq_6.user__bio_added_ts__extract_day - , subq_6.user__bio_added_ts__extract_dow - , subq_6.user__bio_added_ts__extract_doy - , subq_6.user__last_login_ts__minute - , subq_6.user__last_login_ts__hour - , subq_6.user__last_login_ts__day - , subq_6.user__last_login_ts__week - , subq_6.user__last_login_ts__month - , subq_6.user__last_login_ts__quarter - , subq_6.user__last_login_ts__year - , subq_6.user__last_login_ts__extract_year - , subq_6.user__last_login_ts__extract_quarter - , subq_6.user__last_login_ts__extract_month - , subq_6.user__last_login_ts__extract_day - , subq_6.user__last_login_ts__extract_dow - , subq_6.user__last_login_ts__extract_doy - , subq_6.user__archived_at__hour - , subq_6.user__archived_at__day - , subq_6.user__archived_at__week - , subq_6.user__archived_at__month - , subq_6.user__archived_at__quarter - , subq_6.user__archived_at__year - , subq_6.user__archived_at__extract_year - , subq_6.user__archived_at__extract_quarter - , subq_6.user__archived_at__extract_month - , subq_6.user__archived_at__extract_day - , subq_6.user__archived_at__extract_dow - , subq_6.user__archived_at__extract_doy - , subq_6.metric_time__day - , subq_6.metric_time__week - , subq_6.metric_time__month - , subq_6.metric_time__quarter - , subq_6.metric_time__year - , subq_6.metric_time__extract_year - , subq_6.metric_time__extract_quarter - , subq_6.metric_time__extract_month - , subq_6.metric_time__extract_day - , subq_6.metric_time__extract_dow - , subq_6.metric_time__extract_doy - , subq_6.user - , subq_6.home_state - , subq_6.user__home_state - FROM ( - -- Metric Time Dimension 'created_at' - SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.created_at__day - , subq_5.created_at__week - , subq_5.created_at__month - , subq_5.created_at__quarter - , subq_5.created_at__year - , subq_5.created_at__extract_year - , subq_5.created_at__extract_quarter - , subq_5.created_at__extract_month - , subq_5.created_at__extract_day - , subq_5.created_at__extract_dow - , subq_5.created_at__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.last_profile_edit_ts__millisecond - , subq_5.last_profile_edit_ts__second - , subq_5.last_profile_edit_ts__minute - , subq_5.last_profile_edit_ts__hour - , subq_5.last_profile_edit_ts__day - , subq_5.last_profile_edit_ts__week - , subq_5.last_profile_edit_ts__month - , subq_5.last_profile_edit_ts__quarter - , subq_5.last_profile_edit_ts__year - , subq_5.last_profile_edit_ts__extract_year - , subq_5.last_profile_edit_ts__extract_quarter - , subq_5.last_profile_edit_ts__extract_month - , subq_5.last_profile_edit_ts__extract_day - , subq_5.last_profile_edit_ts__extract_dow - , subq_5.last_profile_edit_ts__extract_doy - , subq_5.bio_added_ts__second - , subq_5.bio_added_ts__minute - , subq_5.bio_added_ts__hour - , subq_5.bio_added_ts__day - , subq_5.bio_added_ts__week - , subq_5.bio_added_ts__month - , subq_5.bio_added_ts__quarter - , subq_5.bio_added_ts__year - , subq_5.bio_added_ts__extract_year - , subq_5.bio_added_ts__extract_quarter - , subq_5.bio_added_ts__extract_month - , subq_5.bio_added_ts__extract_day - , subq_5.bio_added_ts__extract_dow - , subq_5.bio_added_ts__extract_doy - , subq_5.last_login_ts__minute - , subq_5.last_login_ts__hour - , subq_5.last_login_ts__day - , subq_5.last_login_ts__week - , subq_5.last_login_ts__month - , subq_5.last_login_ts__quarter - , subq_5.last_login_ts__year - , subq_5.last_login_ts__extract_year - , subq_5.last_login_ts__extract_quarter - , subq_5.last_login_ts__extract_month - , subq_5.last_login_ts__extract_day - , subq_5.last_login_ts__extract_dow - , subq_5.last_login_ts__extract_doy - , subq_5.archived_at__hour - , subq_5.archived_at__day - , subq_5.archived_at__week - , subq_5.archived_at__month - , subq_5.archived_at__quarter - , subq_5.archived_at__year - , subq_5.archived_at__extract_year - , subq_5.archived_at__extract_quarter - , subq_5.archived_at__extract_month - , subq_5.archived_at__extract_day - , subq_5.archived_at__extract_dow - , subq_5.archived_at__extract_doy - , subq_5.user__ds__day - , subq_5.user__ds__week - , subq_5.user__ds__month - , subq_5.user__ds__quarter - , subq_5.user__ds__year - , subq_5.user__ds__extract_year - , subq_5.user__ds__extract_quarter - , subq_5.user__ds__extract_month - , subq_5.user__ds__extract_day - , subq_5.user__ds__extract_dow - , subq_5.user__ds__extract_doy - , subq_5.user__created_at__day - , subq_5.user__created_at__week - , subq_5.user__created_at__month - , subq_5.user__created_at__quarter - , subq_5.user__created_at__year - , subq_5.user__created_at__extract_year - , subq_5.user__created_at__extract_quarter - , subq_5.user__created_at__extract_month - , subq_5.user__created_at__extract_day - , subq_5.user__created_at__extract_dow - , subq_5.user__created_at__extract_doy - , subq_5.user__ds_partitioned__day - , subq_5.user__ds_partitioned__week - , subq_5.user__ds_partitioned__month - , subq_5.user__ds_partitioned__quarter - , subq_5.user__ds_partitioned__year - , subq_5.user__ds_partitioned__extract_year - , subq_5.user__ds_partitioned__extract_quarter - , subq_5.user__ds_partitioned__extract_month - , subq_5.user__ds_partitioned__extract_day - , subq_5.user__ds_partitioned__extract_dow - , subq_5.user__ds_partitioned__extract_doy - , subq_5.user__last_profile_edit_ts__millisecond - , subq_5.user__last_profile_edit_ts__second - , subq_5.user__last_profile_edit_ts__minute - , subq_5.user__last_profile_edit_ts__hour - , subq_5.user__last_profile_edit_ts__day - , subq_5.user__last_profile_edit_ts__week - , subq_5.user__last_profile_edit_ts__month - , subq_5.user__last_profile_edit_ts__quarter - , subq_5.user__last_profile_edit_ts__year - , subq_5.user__last_profile_edit_ts__extract_year - , subq_5.user__last_profile_edit_ts__extract_quarter - , subq_5.user__last_profile_edit_ts__extract_month - , subq_5.user__last_profile_edit_ts__extract_day - , subq_5.user__last_profile_edit_ts__extract_dow - , subq_5.user__last_profile_edit_ts__extract_doy - , subq_5.user__bio_added_ts__second - , subq_5.user__bio_added_ts__minute - , subq_5.user__bio_added_ts__hour - , subq_5.user__bio_added_ts__day - , subq_5.user__bio_added_ts__week - , subq_5.user__bio_added_ts__month - , subq_5.user__bio_added_ts__quarter - , subq_5.user__bio_added_ts__year - , subq_5.user__bio_added_ts__extract_year - , subq_5.user__bio_added_ts__extract_quarter - , subq_5.user__bio_added_ts__extract_month - , subq_5.user__bio_added_ts__extract_day - , subq_5.user__bio_added_ts__extract_dow - , subq_5.user__bio_added_ts__extract_doy - , subq_5.user__last_login_ts__minute - , subq_5.user__last_login_ts__hour - , subq_5.user__last_login_ts__day - , subq_5.user__last_login_ts__week - , subq_5.user__last_login_ts__month - , subq_5.user__last_login_ts__quarter - , subq_5.user__last_login_ts__year - , subq_5.user__last_login_ts__extract_year - , subq_5.user__last_login_ts__extract_quarter - , subq_5.user__last_login_ts__extract_month - , subq_5.user__last_login_ts__extract_day - , subq_5.user__last_login_ts__extract_dow - , subq_5.user__last_login_ts__extract_doy - , subq_5.user__archived_at__hour - , subq_5.user__archived_at__day - , subq_5.user__archived_at__week - , subq_5.user__archived_at__month - , subq_5.user__archived_at__quarter - , subq_5.user__archived_at__year - , subq_5.user__archived_at__extract_year - , subq_5.user__archived_at__extract_quarter - , subq_5.user__archived_at__extract_month - , subq_5.user__archived_at__extract_day - , subq_5.user__archived_at__extract_dow - , subq_5.user__archived_at__extract_doy - , subq_5.created_at__day AS metric_time__day - , subq_5.created_at__week AS metric_time__week - , subq_5.created_at__month AS metric_time__month - , subq_5.created_at__quarter AS metric_time__quarter - , subq_5.created_at__year AS metric_time__year - , subq_5.created_at__extract_year AS metric_time__extract_year - , subq_5.created_at__extract_quarter AS metric_time__extract_quarter - , subq_5.created_at__extract_month AS metric_time__extract_month - , subq_5.created_at__extract_day AS metric_time__extract_day - , subq_5.created_at__extract_dow AS metric_time__extract_dow - , subq_5.created_at__extract_doy AS metric_time__extract_doy - , subq_5.user - , subq_5.home_state - , subq_5.user__home_state - , subq_5.new_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_5 - ) subq_6 - ) subq_7 - ON - subq_4.user = subq_7.user - ) subq_8 - ) subq_9 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_4 + ) subq_5 ON - ( - subq_2.listing = subq_9.listing - ) AND ( - subq_2.ds_partitioned__day = subq_9.user__ds_partitioned__day - ) - ) subq_10 - ) subq_11 + subq_3.user = subq_5.user + ) subq_6 + ON + ( + subq_1.listing = subq_6.listing + ) AND ( + subq_1.ds_partitioned__day = subq_6.ds_partitioned__day + ) + ) subq_7 GROUP BY - subq_11.listing__user__bio_added_ts__minute -) subq_12 + subq_7.listing__user__bio_added_ts__minute +) subq_8 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0_optimized.sql index d93a3918ba..a4d8aadad8 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_joined_sub_daily_dimension__plan0_optimized.sql @@ -3,8 +3,8 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.user__bio_added_ts__minute AS listing__user__bio_added_ts__minute - , SUM(subq_15.bookings) AS bookings + subq_16.listing__user__bio_added_ts__minute AS listing__user__bio_added_ts__minute + , SUM(subq_10.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -14,25 +14,23 @@ FROM ( , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_15 +) subq_10 LEFT OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['user__ds_partitioned__day', 'user__bio_added_ts__minute', 'listing'] SELECT - DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , listings_latest_src_28000.listing_id AS listing + listings_latest_src_28000.listing_id AS listing FROM ***************************.dim_listings_latest listings_latest_src_28000 LEFT OUTER JOIN ***************************.dim_users users_ds_source_src_28000 ON listings_latest_src_28000.user_id = users_ds_source_src_28000.user_id -) subq_22 +) subq_15 ON ( - subq_15.listing = subq_22.listing + subq_10.listing = subq_15.listing ) AND ( - subq_15.ds_partitioned__day = subq_22.user__ds_partitioned__day + subq_10.ds_partitioned__day = subq_15.ds_partitioned__day ) GROUP BY - subq_22.user__bio_added_ts__minute + subq_16.listing__user__bio_added_ts__minute diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0.sql index e1d3b4b02c..b163e636ed 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0.sql @@ -1,395 +1,203 @@ -- Compute Metrics via Expressions SELECT - subq_3.user__archived_at__hour - , subq_3.new_users + subq_2.user__archived_at__hour + , subq_2.new_users FROM ( -- Aggregate Measures SELECT - subq_2.user__archived_at__hour - , SUM(subq_2.new_users) AS new_users + subq_1.user__archived_at__hour + , SUM(subq_1.new_users) AS new_users FROM ( + -- Metric Time Dimension 'created_at' -- Pass Only Elements: ['new_users', 'user__archived_at__hour'] SELECT - subq_1.user__archived_at__hour - , subq_1.new_users + subq_0.user__archived_at__hour + , subq_0.new_users FROM ( - -- Metric Time Dimension 'created_at' + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second - , subq_0.bio_added_ts__minute - , subq_0.bio_added_ts__hour - , subq_0.bio_added_ts__day - , subq_0.bio_added_ts__week - , subq_0.bio_added_ts__month - , subq_0.bio_added_ts__quarter - , subq_0.bio_added_ts__year - , subq_0.bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy - , subq_0.last_login_ts__minute - , subq_0.last_login_ts__hour - , subq_0.last_login_ts__day - , subq_0.last_login_ts__week - , subq_0.last_login_ts__month - , subq_0.last_login_ts__quarter - , subq_0.last_login_ts__year - , subq_0.last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month - , subq_0.last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy - , subq_0.archived_at__hour - , subq_0.archived_at__day - , subq_0.archived_at__week - , subq_0.archived_at__month - , subq_0.archived_at__quarter - , subq_0.archived_at__year - , subq_0.archived_at__extract_year - , subq_0.archived_at__extract_quarter - , subq_0.archived_at__extract_month - , subq_0.archived_at__extract_day - , subq_0.archived_at__extract_dow - , subq_0.archived_at__extract_doy - , subq_0.user__ds__day - , subq_0.user__ds__week - , subq_0.user__ds__month - , subq_0.user__ds__quarter - , subq_0.user__ds__year - , subq_0.user__ds__extract_year - , subq_0.user__ds__extract_quarter - , subq_0.user__ds__extract_month - , subq_0.user__ds__extract_day - , subq_0.user__ds__extract_dow - , subq_0.user__ds__extract_doy - , subq_0.user__created_at__day - , subq_0.user__created_at__week - , subq_0.user__created_at__month - , subq_0.user__created_at__quarter - , subq_0.user__created_at__year - , subq_0.user__created_at__extract_year - , subq_0.user__created_at__extract_quarter - , subq_0.user__created_at__extract_month - , subq_0.user__created_at__extract_day - , subq_0.user__created_at__extract_dow - , subq_0.user__created_at__extract_doy - , subq_0.user__ds_partitioned__day - , subq_0.user__ds_partitioned__week - , subq_0.user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day - , subq_0.user__bio_added_ts__week - , subq_0.user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute - , subq_0.user__last_login_ts__hour - , subq_0.user__last_login_ts__day - , subq_0.user__last_login_ts__week - , subq_0.user__last_login_ts__month - , subq_0.user__last_login_ts__quarter - , subq_0.user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour - , subq_0.user__archived_at__day - , subq_0.user__archived_at__week - , subq_0.user__archived_at__month - , subq_0.user__archived_at__quarter - , subq_0.user__archived_at__year - , subq_0.user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month - , subq_0.user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy - , subq_0.created_at__day AS metric_time__day - , subq_0.created_at__week AS metric_time__week - , subq_0.created_at__month AS metric_time__month - , subq_0.created_at__quarter AS metric_time__quarter - , subq_0.created_at__year AS metric_time__year - , subq_0.created_at__extract_year AS metric_time__extract_year - , subq_0.created_at__extract_quarter AS metric_time__extract_quarter - , subq_0.created_at__extract_month AS metric_time__extract_month - , subq_0.created_at__extract_day AS metric_time__extract_day - , subq_0.created_at__extract_dow AS metric_time__extract_dow - , subq_0.created_at__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.home_state - , subq_0.user__home_state - , subq_0.new_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.user__archived_at__hour -) subq_3 + subq_1.user__archived_at__hour +) subq_2 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0_optimized.sql index c20146c881..682eb7c94b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_metric_with_sub_daily_dimension__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ( DATE_TRUNC('hour', archived_at) AS user__archived_at__hour , 1 AS new_users FROM ***************************.dim_users users_ds_source_src_28000 -) subq_6 +) subq_4 GROUP BY user__archived_at__hour diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_date_part__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_date_part__plan0.sql index c8bfaf1393..7a523aef4f 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_date_part__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_date_part__plan0.sql @@ -1,213 +1,112 @@ -- Compute Metrics via Expressions SELECT - subq_3.metric_time__extract_dow - , subq_3.bookings + subq_2.metric_time__extract_dow + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__extract_dow - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__extract_dow + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__extract_dow'] SELECT - subq_1.metric_time__extract_dow - , subq_1.bookings + subq_0.ds__extract_dow AS metric_time__extract_dow + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__extract_dow -) subq_3 + subq_1.metric_time__extract_dow +) subq_2 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_date_part__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_date_part__plan0_optimized.sql index 6f941d2507..fce5e98186 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_date_part__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_date_part__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ( EXTRACT(isodow FROM ds) AS metric_time__extract_dow , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_6 +) subq_4 GROUP BY metric_time__extract_dow diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_multiple_date_parts__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_multiple_date_parts__plan0.sql index dce9e5edd0..949410bc7b 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_multiple_date_parts__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_multiple_date_parts__plan0.sql @@ -1,23 +1,24 @@ -- Compute Metrics via Expressions SELECT - subq_3.metric_time__extract_year - , subq_3.metric_time__extract_quarter - , subq_3.metric_time__extract_month - , subq_3.metric_time__extract_day - , subq_3.metric_time__extract_dow - , subq_3.metric_time__extract_doy - , subq_3.bookings + 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.bookings FROM ( -- Aggregate Measures SELECT - 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 - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__extract_year + , subq_1.metric_time__extract_quarter + , subq_1.metric_time__extract_month + , subq_1.metric_time__extract_day + , subq_1.metric_time__extract_dow + , subq_1.metric_time__extract_doy + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: [ -- 'bookings', -- 'metric_time__extract_day', @@ -28,214 +29,112 @@ FROM ( -- 'metric_time__extract_year', -- ] SELECT - subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.bookings + 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.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - 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_3 + subq_1.metric_time__extract_year + , subq_1.metric_time__extract_quarter + , subq_1.metric_time__extract_month + , subq_1.metric_time__extract_day + , subq_1.metric_time__extract_dow + , subq_1.metric_time__extract_doy +) subq_2 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_multiple_date_parts__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_multiple_date_parts__plan0_optimized.sql index f99f93118d..20366856ec 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_multiple_date_parts__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_simple_query_with_multiple_date_parts__plan0_optimized.sql @@ -29,7 +29,7 @@ FROM ( , EXTRACT(doy FROM ds) AS metric_time__extract_doy , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_6 +) subq_4 GROUP BY metric_time__extract_year , metric_time__extract_quarter diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0.sql index e10224debe..df11ab1316 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0.sql @@ -1,189 +1,7 @@ +-- Read From SemanticModelDataSet('users_ds_source') -- Pass Only Elements: ['user__bio_added_ts__second',] SELECT - subq_0.user__bio_added_ts__second -FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 -) subq_0 + DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second +FROM ***************************.dim_users users_ds_source_src_28000 GROUP BY - subq_0.user__bio_added_ts__second + DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0_optimized.sql index b7bf7d7395..0a83dc5af0 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_dimension__plan0_optimized.sql @@ -1,4 +1,4 @@ --- Read Elements From Semantic Model 'users_ds_source' +-- Read From SemanticModelDataSet('users_ds_source') -- Pass Only Elements: ['user__bio_added_ts__second',] SELECT DATE_TRUNC('second', bio_added_ts) AS user__bio_added_ts__second diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_metric_time__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_metric_time__plan0.sql index 4507843952..896e424ea7 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_sub_daily_metric_time__plan0.sql @@ -1,59 +1,26 @@ +-- Metric Time Dimension 'ts' -- Pass Only Elements: ['metric_time__millisecond',] SELECT - subq_1.metric_time__millisecond + subq_0.ts__millisecond AS metric_time__millisecond FROM ( - -- Metric Time Dimension 'ts' + -- Time Spine SELECT - subq_0.ts__millisecond - , subq_0.ts__second - , subq_0.ts__minute - , subq_0.ts__hour - , subq_0.ts__day - , subq_0.ts__week - , subq_0.ts__month - , subq_0.ts__quarter - , subq_0.ts__year - , subq_0.ts__extract_year - , subq_0.ts__extract_quarter - , subq_0.ts__extract_month - , subq_0.ts__extract_day - , subq_0.ts__extract_dow - , subq_0.ts__extract_doy - , subq_0.ts__millisecond AS metric_time__millisecond - , subq_0.ts__second AS metric_time__second - , subq_0.ts__minute AS metric_time__minute - , subq_0.ts__hour AS metric_time__hour - , subq_0.ts__day AS metric_time__day - , subq_0.ts__week AS metric_time__week - , subq_0.ts__month AS metric_time__month - , subq_0.ts__quarter AS metric_time__quarter - , subq_0.ts__year AS metric_time__year - , subq_0.ts__extract_year AS metric_time__extract_year - , subq_0.ts__extract_quarter AS metric_time__extract_quarter - , subq_0.ts__extract_month AS metric_time__extract_month - , subq_0.ts__extract_day AS metric_time__extract_day - , subq_0.ts__extract_dow AS metric_time__extract_dow - , subq_0.ts__extract_doy AS metric_time__extract_doy - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond - , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second - , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute - , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour - , DATE_TRUNC('day', time_spine_src_28002.ts) AS ts__day - , DATE_TRUNC('week', time_spine_src_28002.ts) AS ts__week - , DATE_TRUNC('month', time_spine_src_28002.ts) AS ts__month - , DATE_TRUNC('quarter', time_spine_src_28002.ts) AS ts__quarter - , DATE_TRUNC('year', time_spine_src_28002.ts) AS ts__year - , EXTRACT(year FROM time_spine_src_28002.ts) AS ts__extract_year - , EXTRACT(quarter FROM time_spine_src_28002.ts) AS ts__extract_quarter - , EXTRACT(month FROM time_spine_src_28002.ts) AS ts__extract_month - , EXTRACT(day FROM time_spine_src_28002.ts) AS ts__extract_day - , EXTRACT(isodow FROM time_spine_src_28002.ts) AS ts__extract_dow - , EXTRACT(doy FROM time_spine_src_28002.ts) AS ts__extract_doy - FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 - ) subq_0 -) subq_1 + DATE_TRUNC('millisecond', time_spine_src_28002.ts) AS ts__millisecond + , DATE_TRUNC('second', time_spine_src_28002.ts) AS ts__second + , DATE_TRUNC('minute', time_spine_src_28002.ts) AS ts__minute + , DATE_TRUNC('hour', time_spine_src_28002.ts) AS ts__hour + , DATE_TRUNC('day', time_spine_src_28002.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28002.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28002.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28002.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28002.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28002.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28002.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28002.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28002.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28002.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28002.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_millisecond time_spine_src_28002 +) subq_0 GROUP BY - subq_1.metric_time__millisecond + subq_0.ts__millisecond diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0.sql index 1a252f2ebe..93a38d0d71 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0.sql @@ -1,602 +1,409 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_cumulative_grain_to_date_metric + subq_5.metric_time__hour + , subq_5.archived_users AS subdaily_cumulative_grain_to_date_metric FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_4.metric_time__hour + , SUM(subq_4.archived_users) AS archived_users FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_2.metric_time__hour AS metric_time__hour + , subq_1.archived_users AS archived_users FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__hour AS metric_time__hour - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.created_at__day AS created_at__day - , subq_1.created_at__week AS created_at__week - , subq_1.created_at__month AS created_at__month - , subq_1.created_at__quarter AS created_at__quarter - , subq_1.created_at__year AS created_at__year - , subq_1.created_at__extract_year AS created_at__extract_year - , subq_1.created_at__extract_quarter AS created_at__extract_quarter - , subq_1.created_at__extract_month AS created_at__extract_month - , subq_1.created_at__extract_day AS created_at__extract_day - , subq_1.created_at__extract_dow AS created_at__extract_dow - , subq_1.created_at__extract_doy AS created_at__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.last_profile_edit_ts__millisecond AS last_profile_edit_ts__millisecond - , subq_1.last_profile_edit_ts__second AS last_profile_edit_ts__second - , subq_1.last_profile_edit_ts__minute AS last_profile_edit_ts__minute - , subq_1.last_profile_edit_ts__hour AS last_profile_edit_ts__hour - , subq_1.last_profile_edit_ts__day AS last_profile_edit_ts__day - , subq_1.last_profile_edit_ts__week AS last_profile_edit_ts__week - , subq_1.last_profile_edit_ts__month AS last_profile_edit_ts__month - , subq_1.last_profile_edit_ts__quarter AS last_profile_edit_ts__quarter - , subq_1.last_profile_edit_ts__year AS last_profile_edit_ts__year - , subq_1.last_profile_edit_ts__extract_year AS last_profile_edit_ts__extract_year - , subq_1.last_profile_edit_ts__extract_quarter AS last_profile_edit_ts__extract_quarter - , subq_1.last_profile_edit_ts__extract_month AS last_profile_edit_ts__extract_month - , subq_1.last_profile_edit_ts__extract_day AS last_profile_edit_ts__extract_day - , subq_1.last_profile_edit_ts__extract_dow AS last_profile_edit_ts__extract_dow - , subq_1.last_profile_edit_ts__extract_doy AS last_profile_edit_ts__extract_doy - , subq_1.bio_added_ts__second AS bio_added_ts__second - , subq_1.bio_added_ts__minute AS bio_added_ts__minute - , subq_1.bio_added_ts__hour AS bio_added_ts__hour - , subq_1.bio_added_ts__day AS bio_added_ts__day - , subq_1.bio_added_ts__week AS bio_added_ts__week - , subq_1.bio_added_ts__month AS bio_added_ts__month - , subq_1.bio_added_ts__quarter AS bio_added_ts__quarter - , subq_1.bio_added_ts__year AS bio_added_ts__year - , subq_1.bio_added_ts__extract_year AS bio_added_ts__extract_year - , subq_1.bio_added_ts__extract_quarter AS bio_added_ts__extract_quarter - , subq_1.bio_added_ts__extract_month AS bio_added_ts__extract_month - , subq_1.bio_added_ts__extract_day AS bio_added_ts__extract_day - , subq_1.bio_added_ts__extract_dow AS bio_added_ts__extract_dow - , subq_1.bio_added_ts__extract_doy AS bio_added_ts__extract_doy - , subq_1.last_login_ts__minute AS last_login_ts__minute - , subq_1.last_login_ts__hour AS last_login_ts__hour - , subq_1.last_login_ts__day AS last_login_ts__day - , subq_1.last_login_ts__week AS last_login_ts__week - , subq_1.last_login_ts__month AS last_login_ts__month - , subq_1.last_login_ts__quarter AS last_login_ts__quarter - , subq_1.last_login_ts__year AS last_login_ts__year - , subq_1.last_login_ts__extract_year AS last_login_ts__extract_year - , subq_1.last_login_ts__extract_quarter AS last_login_ts__extract_quarter - , subq_1.last_login_ts__extract_month AS last_login_ts__extract_month - , subq_1.last_login_ts__extract_day AS last_login_ts__extract_day - , subq_1.last_login_ts__extract_dow AS last_login_ts__extract_dow - , subq_1.last_login_ts__extract_doy AS last_login_ts__extract_doy - , subq_1.archived_at__hour AS archived_at__hour - , subq_1.archived_at__day AS archived_at__day - , subq_1.archived_at__week AS archived_at__week - , subq_1.archived_at__month AS archived_at__month - , subq_1.archived_at__quarter AS archived_at__quarter - , subq_1.archived_at__year AS archived_at__year - , subq_1.archived_at__extract_year AS archived_at__extract_year - , subq_1.archived_at__extract_quarter AS archived_at__extract_quarter - , subq_1.archived_at__extract_month AS archived_at__extract_month - , subq_1.archived_at__extract_day AS archived_at__extract_day - , subq_1.archived_at__extract_dow AS archived_at__extract_dow - , subq_1.archived_at__extract_doy AS archived_at__extract_doy - , subq_1.user__ds__day AS user__ds__day - , subq_1.user__ds__week AS user__ds__week - , subq_1.user__ds__month AS user__ds__month - , subq_1.user__ds__quarter AS user__ds__quarter - , subq_1.user__ds__year AS user__ds__year - , subq_1.user__ds__extract_year AS user__ds__extract_year - , subq_1.user__ds__extract_quarter AS user__ds__extract_quarter - , subq_1.user__ds__extract_month AS user__ds__extract_month - , subq_1.user__ds__extract_day AS user__ds__extract_day - , subq_1.user__ds__extract_dow AS user__ds__extract_dow - , subq_1.user__ds__extract_doy AS user__ds__extract_doy - , subq_1.user__created_at__day AS user__created_at__day - , subq_1.user__created_at__week AS user__created_at__week - , subq_1.user__created_at__month AS user__created_at__month - , subq_1.user__created_at__quarter AS user__created_at__quarter - , subq_1.user__created_at__year AS user__created_at__year - , subq_1.user__created_at__extract_year AS user__created_at__extract_year - , subq_1.user__created_at__extract_quarter AS user__created_at__extract_quarter - , subq_1.user__created_at__extract_month AS user__created_at__extract_month - , subq_1.user__created_at__extract_day AS user__created_at__extract_day - , subq_1.user__created_at__extract_dow AS user__created_at__extract_dow - , subq_1.user__created_at__extract_doy AS user__created_at__extract_doy - , subq_1.user__ds_partitioned__day AS user__ds_partitioned__day - , subq_1.user__ds_partitioned__week AS user__ds_partitioned__week - , subq_1.user__ds_partitioned__month AS user__ds_partitioned__month - , subq_1.user__ds_partitioned__quarter AS user__ds_partitioned__quarter - , subq_1.user__ds_partitioned__year AS user__ds_partitioned__year - , subq_1.user__ds_partitioned__extract_year AS user__ds_partitioned__extract_year - , subq_1.user__ds_partitioned__extract_quarter AS user__ds_partitioned__extract_quarter - , subq_1.user__ds_partitioned__extract_month AS user__ds_partitioned__extract_month - , subq_1.user__ds_partitioned__extract_day AS user__ds_partitioned__extract_day - , subq_1.user__ds_partitioned__extract_dow AS user__ds_partitioned__extract_dow - , subq_1.user__ds_partitioned__extract_doy AS user__ds_partitioned__extract_doy - , subq_1.user__last_profile_edit_ts__millisecond AS user__last_profile_edit_ts__millisecond - , subq_1.user__last_profile_edit_ts__second AS user__last_profile_edit_ts__second - , subq_1.user__last_profile_edit_ts__minute AS user__last_profile_edit_ts__minute - , subq_1.user__last_profile_edit_ts__hour AS user__last_profile_edit_ts__hour - , subq_1.user__last_profile_edit_ts__day AS user__last_profile_edit_ts__day - , subq_1.user__last_profile_edit_ts__week AS user__last_profile_edit_ts__week - , subq_1.user__last_profile_edit_ts__month AS user__last_profile_edit_ts__month - , subq_1.user__last_profile_edit_ts__quarter AS user__last_profile_edit_ts__quarter - , subq_1.user__last_profile_edit_ts__year AS user__last_profile_edit_ts__year - , subq_1.user__last_profile_edit_ts__extract_year AS user__last_profile_edit_ts__extract_year - , subq_1.user__last_profile_edit_ts__extract_quarter AS user__last_profile_edit_ts__extract_quarter - , subq_1.user__last_profile_edit_ts__extract_month AS user__last_profile_edit_ts__extract_month - , subq_1.user__last_profile_edit_ts__extract_day AS user__last_profile_edit_ts__extract_day - , subq_1.user__last_profile_edit_ts__extract_dow AS user__last_profile_edit_ts__extract_dow - , subq_1.user__last_profile_edit_ts__extract_doy AS user__last_profile_edit_ts__extract_doy - , subq_1.user__bio_added_ts__second AS user__bio_added_ts__second - , subq_1.user__bio_added_ts__minute AS user__bio_added_ts__minute - , subq_1.user__bio_added_ts__hour AS user__bio_added_ts__hour - , subq_1.user__bio_added_ts__day AS user__bio_added_ts__day - , subq_1.user__bio_added_ts__week AS user__bio_added_ts__week - , subq_1.user__bio_added_ts__month AS user__bio_added_ts__month - , subq_1.user__bio_added_ts__quarter AS user__bio_added_ts__quarter - , subq_1.user__bio_added_ts__year AS user__bio_added_ts__year - , subq_1.user__bio_added_ts__extract_year AS user__bio_added_ts__extract_year - , subq_1.user__bio_added_ts__extract_quarter AS user__bio_added_ts__extract_quarter - , subq_1.user__bio_added_ts__extract_month AS user__bio_added_ts__extract_month - , subq_1.user__bio_added_ts__extract_day AS user__bio_added_ts__extract_day - , subq_1.user__bio_added_ts__extract_dow AS user__bio_added_ts__extract_dow - , subq_1.user__bio_added_ts__extract_doy AS user__bio_added_ts__extract_doy - , subq_1.user__last_login_ts__minute AS user__last_login_ts__minute - , subq_1.user__last_login_ts__hour AS user__last_login_ts__hour - , subq_1.user__last_login_ts__day AS user__last_login_ts__day - , subq_1.user__last_login_ts__week AS user__last_login_ts__week - , subq_1.user__last_login_ts__month AS user__last_login_ts__month - , subq_1.user__last_login_ts__quarter AS user__last_login_ts__quarter - , subq_1.user__last_login_ts__year AS user__last_login_ts__year - , subq_1.user__last_login_ts__extract_year AS user__last_login_ts__extract_year - , subq_1.user__last_login_ts__extract_quarter AS user__last_login_ts__extract_quarter - , subq_1.user__last_login_ts__extract_month AS user__last_login_ts__extract_month - , subq_1.user__last_login_ts__extract_day AS user__last_login_ts__extract_day - , subq_1.user__last_login_ts__extract_dow AS user__last_login_ts__extract_dow - , subq_1.user__last_login_ts__extract_doy AS user__last_login_ts__extract_doy - , subq_1.user__archived_at__hour AS user__archived_at__hour - , subq_1.user__archived_at__day AS user__archived_at__day - , subq_1.user__archived_at__week AS user__archived_at__week - , subq_1.user__archived_at__month AS user__archived_at__month - , subq_1.user__archived_at__quarter AS user__archived_at__quarter - , subq_1.user__archived_at__year AS user__archived_at__year - , subq_1.user__archived_at__extract_year AS user__archived_at__extract_year - , subq_1.user__archived_at__extract_quarter AS user__archived_at__extract_quarter - , subq_1.user__archived_at__extract_month AS user__archived_at__extract_month - , subq_1.user__archived_at__extract_day AS user__archived_at__extract_day - , subq_1.user__archived_at__extract_dow AS user__archived_at__extract_dow - , subq_1.user__archived_at__extract_doy AS user__archived_at__extract_doy - , subq_1.metric_time__day AS metric_time__day - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_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 + subq_3.ts AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'archived_at' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.created_at__day + , subq_0.created_at__week + , subq_0.created_at__month + , subq_0.created_at__quarter + , subq_0.created_at__year + , subq_0.created_at__extract_year + , subq_0.created_at__extract_quarter + , subq_0.created_at__extract_month + , subq_0.created_at__extract_day + , subq_0.created_at__extract_dow + , subq_0.created_at__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.last_profile_edit_ts__millisecond + , subq_0.last_profile_edit_ts__second + , subq_0.last_profile_edit_ts__minute + , subq_0.last_profile_edit_ts__hour + , subq_0.last_profile_edit_ts__day + , subq_0.last_profile_edit_ts__week + , subq_0.last_profile_edit_ts__month + , subq_0.last_profile_edit_ts__quarter + , subq_0.last_profile_edit_ts__year + , subq_0.last_profile_edit_ts__extract_year + , subq_0.last_profile_edit_ts__extract_quarter + , subq_0.last_profile_edit_ts__extract_month + , subq_0.last_profile_edit_ts__extract_day + , subq_0.last_profile_edit_ts__extract_dow + , subq_0.last_profile_edit_ts__extract_doy + , subq_0.bio_added_ts__second + , subq_0.bio_added_ts__minute + , subq_0.bio_added_ts__hour + , subq_0.bio_added_ts__day + , subq_0.bio_added_ts__week + , subq_0.bio_added_ts__month + , subq_0.bio_added_ts__quarter + , subq_0.bio_added_ts__year + , subq_0.bio_added_ts__extract_year + , subq_0.bio_added_ts__extract_quarter + , subq_0.bio_added_ts__extract_month + , subq_0.bio_added_ts__extract_day + , subq_0.bio_added_ts__extract_dow + , subq_0.bio_added_ts__extract_doy + , subq_0.last_login_ts__minute + , subq_0.last_login_ts__hour + , subq_0.last_login_ts__day + , subq_0.last_login_ts__week + , subq_0.last_login_ts__month + , subq_0.last_login_ts__quarter + , subq_0.last_login_ts__year + , subq_0.last_login_ts__extract_year + , subq_0.last_login_ts__extract_quarter + , subq_0.last_login_ts__extract_month + , subq_0.last_login_ts__extract_day + , subq_0.last_login_ts__extract_dow + , subq_0.last_login_ts__extract_doy + , subq_0.archived_at__hour + , subq_0.archived_at__day + , subq_0.archived_at__week + , subq_0.archived_at__month + , subq_0.archived_at__quarter + , subq_0.archived_at__year + , subq_0.archived_at__extract_year + , subq_0.archived_at__extract_quarter + , subq_0.archived_at__extract_month + , subq_0.archived_at__extract_day + , subq_0.archived_at__extract_dow + , subq_0.archived_at__extract_doy + , subq_0.user__ds__day + , subq_0.user__ds__week + , subq_0.user__ds__month + , subq_0.user__ds__quarter + , subq_0.user__ds__year + , subq_0.user__ds__extract_year + , subq_0.user__ds__extract_quarter + , subq_0.user__ds__extract_month + , subq_0.user__ds__extract_day + , subq_0.user__ds__extract_dow + , subq_0.user__ds__extract_doy + , subq_0.user__created_at__day + , subq_0.user__created_at__week + , subq_0.user__created_at__month + , subq_0.user__created_at__quarter + , subq_0.user__created_at__year + , subq_0.user__created_at__extract_year + , subq_0.user__created_at__extract_quarter + , subq_0.user__created_at__extract_month + , subq_0.user__created_at__extract_day + , subq_0.user__created_at__extract_dow + , subq_0.user__created_at__extract_doy + , subq_0.user__ds_partitioned__day + , subq_0.user__ds_partitioned__week + , subq_0.user__ds_partitioned__month + , subq_0.user__ds_partitioned__quarter + , subq_0.user__ds_partitioned__year + , subq_0.user__ds_partitioned__extract_year + , subq_0.user__ds_partitioned__extract_quarter + , subq_0.user__ds_partitioned__extract_month + , subq_0.user__ds_partitioned__extract_day + , subq_0.user__ds_partitioned__extract_dow + , subq_0.user__ds_partitioned__extract_doy + , subq_0.user__last_profile_edit_ts__millisecond + , subq_0.user__last_profile_edit_ts__second + , subq_0.user__last_profile_edit_ts__minute + , subq_0.user__last_profile_edit_ts__hour + , subq_0.user__last_profile_edit_ts__day + , subq_0.user__last_profile_edit_ts__week + , subq_0.user__last_profile_edit_ts__month + , subq_0.user__last_profile_edit_ts__quarter + , subq_0.user__last_profile_edit_ts__year + , subq_0.user__last_profile_edit_ts__extract_year + , subq_0.user__last_profile_edit_ts__extract_quarter + , subq_0.user__last_profile_edit_ts__extract_month + , subq_0.user__last_profile_edit_ts__extract_day + , subq_0.user__last_profile_edit_ts__extract_dow + , subq_0.user__last_profile_edit_ts__extract_doy + , subq_0.user__bio_added_ts__second + , subq_0.user__bio_added_ts__minute + , subq_0.user__bio_added_ts__hour + , subq_0.user__bio_added_ts__day + , subq_0.user__bio_added_ts__week + , subq_0.user__bio_added_ts__month + , subq_0.user__bio_added_ts__quarter + , subq_0.user__bio_added_ts__year + , subq_0.user__bio_added_ts__extract_year + , subq_0.user__bio_added_ts__extract_quarter + , subq_0.user__bio_added_ts__extract_month + , subq_0.user__bio_added_ts__extract_day + , subq_0.user__bio_added_ts__extract_dow + , subq_0.user__bio_added_ts__extract_doy + , subq_0.user__last_login_ts__minute + , subq_0.user__last_login_ts__hour + , subq_0.user__last_login_ts__day + , subq_0.user__last_login_ts__week + , subq_0.user__last_login_ts__month + , subq_0.user__last_login_ts__quarter + , subq_0.user__last_login_ts__year + , subq_0.user__last_login_ts__extract_year + , subq_0.user__last_login_ts__extract_quarter + , subq_0.user__last_login_ts__extract_month + , subq_0.user__last_login_ts__extract_day + , subq_0.user__last_login_ts__extract_dow + , subq_0.user__last_login_ts__extract_doy + , subq_0.user__archived_at__hour + , subq_0.user__archived_at__day + , subq_0.user__archived_at__week + , subq_0.user__archived_at__month + , subq_0.user__archived_at__quarter + , subq_0.user__archived_at__year + , subq_0.user__archived_at__extract_year + , subq_0.user__archived_at__extract_quarter + , subq_0.user__archived_at__extract_month + , subq_0.user__archived_at__extract_day + , subq_0.user__archived_at__extract_dow + , subq_0.user__archived_at__extract_doy + , subq_0.archived_at__hour AS metric_time__hour + , subq_0.archived_at__day AS metric_time__day + , subq_0.archived_at__week AS metric_time__week + , subq_0.archived_at__month AS metric_time__month + , subq_0.archived_at__quarter AS metric_time__quarter + , subq_0.archived_at__year AS metric_time__year + , subq_0.archived_at__extract_year AS metric_time__extract_year + , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter + , subq_0.archived_at__extract_month AS metric_time__extract_month + , subq_0.archived_at__extract_day AS metric_time__extract_day + , subq_0.archived_at__extract_dow AS metric_time__extract_dow + , subq_0.archived_at__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.home_state + , subq_0.user__home_state + , subq_0.archived_users FROM ( - -- Time Spine - SELECT - subq_3.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'archived_at' + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second - , subq_0.bio_added_ts__minute - , subq_0.bio_added_ts__hour - , subq_0.bio_added_ts__day - , subq_0.bio_added_ts__week - , subq_0.bio_added_ts__month - , subq_0.bio_added_ts__quarter - , subq_0.bio_added_ts__year - , subq_0.bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy - , subq_0.last_login_ts__minute - , subq_0.last_login_ts__hour - , subq_0.last_login_ts__day - , subq_0.last_login_ts__week - , subq_0.last_login_ts__month - , subq_0.last_login_ts__quarter - , subq_0.last_login_ts__year - , subq_0.last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month - , subq_0.last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy - , subq_0.archived_at__hour - , subq_0.archived_at__day - , subq_0.archived_at__week - , subq_0.archived_at__month - , subq_0.archived_at__quarter - , subq_0.archived_at__year - , subq_0.archived_at__extract_year - , subq_0.archived_at__extract_quarter - , subq_0.archived_at__extract_month - , subq_0.archived_at__extract_day - , subq_0.archived_at__extract_dow - , subq_0.archived_at__extract_doy - , subq_0.user__ds__day - , subq_0.user__ds__week - , subq_0.user__ds__month - , subq_0.user__ds__quarter - , subq_0.user__ds__year - , subq_0.user__ds__extract_year - , subq_0.user__ds__extract_quarter - , subq_0.user__ds__extract_month - , subq_0.user__ds__extract_day - , subq_0.user__ds__extract_dow - , subq_0.user__ds__extract_doy - , subq_0.user__created_at__day - , subq_0.user__created_at__week - , subq_0.user__created_at__month - , subq_0.user__created_at__quarter - , subq_0.user__created_at__year - , subq_0.user__created_at__extract_year - , subq_0.user__created_at__extract_quarter - , subq_0.user__created_at__extract_month - , subq_0.user__created_at__extract_day - , subq_0.user__created_at__extract_dow - , subq_0.user__created_at__extract_doy - , subq_0.user__ds_partitioned__day - , subq_0.user__ds_partitioned__week - , subq_0.user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day - , subq_0.user__bio_added_ts__week - , subq_0.user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute - , subq_0.user__last_login_ts__hour - , subq_0.user__last_login_ts__day - , subq_0.user__last_login_ts__week - , subq_0.user__last_login_ts__month - , subq_0.user__last_login_ts__quarter - , subq_0.user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour - , subq_0.user__archived_at__day - , subq_0.user__archived_at__week - , subq_0.user__archived_at__month - , subq_0.user__archived_at__quarter - , subq_0.user__archived_at__year - , subq_0.user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month - , subq_0.user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy - , subq_0.archived_at__hour AS metric_time__hour - , subq_0.archived_at__day AS metric_time__day - , subq_0.archived_at__week AS metric_time__week - , subq_0.archived_at__month AS metric_time__month - , subq_0.archived_at__quarter AS metric_time__quarter - , subq_0.archived_at__year AS metric_time__year - , subq_0.archived_at__extract_year AS metric_time__extract_year - , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter - , subq_0.archived_at__extract_month AS metric_time__extract_month - , subq_0.archived_at__extract_day AS metric_time__extract_day - , subq_0.archived_at__extract_dow AS metric_time__extract_dow - , subq_0.archived_at__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.home_state - , subq_0.user__home_state - , subq_0.archived_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__hour <= subq_2.metric_time__hour - ) AND ( - subq_1.metric_time__hour >= DATE_TRUNC('hour', subq_2.metric_time__hour) - ) - ) subq_4 - ) subq_5 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__hour <= subq_2.metric_time__hour + ) AND ( + subq_1.metric_time__hour >= DATE_TRUNC('hour', subq_2.metric_time__hour) + ) + ) subq_4 GROUP BY - subq_5.metric_time__hour -) subq_6 + subq_4.metric_time__hour +) subq_5 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0_optimized.sql index fe834fa9e6..86e45b1d7a 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_grain_to_date_metric__plan0_optimized.sql @@ -3,9 +3,9 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.ts AS metric_time__hour - , SUM(subq_8.archived_users) AS subdaily_cumulative_grain_to_date_metric -FROM ***************************.mf_time_spine_hour subq_10 + subq_9.ts AS metric_time__hour + , SUM(subq_7.archived_users) AS subdaily_cumulative_grain_to_date_metric +FROM ***************************.mf_time_spine_hour subq_9 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -13,12 +13,12 @@ INNER JOIN ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 -) subq_8 +) subq_7 ON ( - subq_8.metric_time__hour <= subq_10.ts + subq_7.metric_time__hour <= subq_9.ts ) AND ( - subq_8.metric_time__hour >= DATE_TRUNC('hour', subq_10.ts) + subq_7.metric_time__hour >= DATE_TRUNC('hour', subq_9.ts) ) GROUP BY - subq_10.ts + subq_9.ts diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0.sql index a18b954931..8b02508622 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0.sql @@ -1,602 +1,409 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_cumulative_window_metric + subq_5.metric_time__hour + , subq_5.archived_users AS subdaily_cumulative_window_metric FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_4.metric_time__hour + , SUM(subq_4.archived_users) AS archived_users FROM ( + -- Join Self Over Time Range -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_2.metric_time__hour AS metric_time__hour + , subq_1.archived_users AS archived_users FROM ( - -- Join Self Over Time Range + -- Time Spine SELECT - subq_2.metric_time__hour AS metric_time__hour - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.created_at__day AS created_at__day - , subq_1.created_at__week AS created_at__week - , subq_1.created_at__month AS created_at__month - , subq_1.created_at__quarter AS created_at__quarter - , subq_1.created_at__year AS created_at__year - , subq_1.created_at__extract_year AS created_at__extract_year - , subq_1.created_at__extract_quarter AS created_at__extract_quarter - , subq_1.created_at__extract_month AS created_at__extract_month - , subq_1.created_at__extract_day AS created_at__extract_day - , subq_1.created_at__extract_dow AS created_at__extract_dow - , subq_1.created_at__extract_doy AS created_at__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.last_profile_edit_ts__millisecond AS last_profile_edit_ts__millisecond - , subq_1.last_profile_edit_ts__second AS last_profile_edit_ts__second - , subq_1.last_profile_edit_ts__minute AS last_profile_edit_ts__minute - , subq_1.last_profile_edit_ts__hour AS last_profile_edit_ts__hour - , subq_1.last_profile_edit_ts__day AS last_profile_edit_ts__day - , subq_1.last_profile_edit_ts__week AS last_profile_edit_ts__week - , subq_1.last_profile_edit_ts__month AS last_profile_edit_ts__month - , subq_1.last_profile_edit_ts__quarter AS last_profile_edit_ts__quarter - , subq_1.last_profile_edit_ts__year AS last_profile_edit_ts__year - , subq_1.last_profile_edit_ts__extract_year AS last_profile_edit_ts__extract_year - , subq_1.last_profile_edit_ts__extract_quarter AS last_profile_edit_ts__extract_quarter - , subq_1.last_profile_edit_ts__extract_month AS last_profile_edit_ts__extract_month - , subq_1.last_profile_edit_ts__extract_day AS last_profile_edit_ts__extract_day - , subq_1.last_profile_edit_ts__extract_dow AS last_profile_edit_ts__extract_dow - , subq_1.last_profile_edit_ts__extract_doy AS last_profile_edit_ts__extract_doy - , subq_1.bio_added_ts__second AS bio_added_ts__second - , subq_1.bio_added_ts__minute AS bio_added_ts__minute - , subq_1.bio_added_ts__hour AS bio_added_ts__hour - , subq_1.bio_added_ts__day AS bio_added_ts__day - , subq_1.bio_added_ts__week AS bio_added_ts__week - , subq_1.bio_added_ts__month AS bio_added_ts__month - , subq_1.bio_added_ts__quarter AS bio_added_ts__quarter - , subq_1.bio_added_ts__year AS bio_added_ts__year - , subq_1.bio_added_ts__extract_year AS bio_added_ts__extract_year - , subq_1.bio_added_ts__extract_quarter AS bio_added_ts__extract_quarter - , subq_1.bio_added_ts__extract_month AS bio_added_ts__extract_month - , subq_1.bio_added_ts__extract_day AS bio_added_ts__extract_day - , subq_1.bio_added_ts__extract_dow AS bio_added_ts__extract_dow - , subq_1.bio_added_ts__extract_doy AS bio_added_ts__extract_doy - , subq_1.last_login_ts__minute AS last_login_ts__minute - , subq_1.last_login_ts__hour AS last_login_ts__hour - , subq_1.last_login_ts__day AS last_login_ts__day - , subq_1.last_login_ts__week AS last_login_ts__week - , subq_1.last_login_ts__month AS last_login_ts__month - , subq_1.last_login_ts__quarter AS last_login_ts__quarter - , subq_1.last_login_ts__year AS last_login_ts__year - , subq_1.last_login_ts__extract_year AS last_login_ts__extract_year - , subq_1.last_login_ts__extract_quarter AS last_login_ts__extract_quarter - , subq_1.last_login_ts__extract_month AS last_login_ts__extract_month - , subq_1.last_login_ts__extract_day AS last_login_ts__extract_day - , subq_1.last_login_ts__extract_dow AS last_login_ts__extract_dow - , subq_1.last_login_ts__extract_doy AS last_login_ts__extract_doy - , subq_1.archived_at__hour AS archived_at__hour - , subq_1.archived_at__day AS archived_at__day - , subq_1.archived_at__week AS archived_at__week - , subq_1.archived_at__month AS archived_at__month - , subq_1.archived_at__quarter AS archived_at__quarter - , subq_1.archived_at__year AS archived_at__year - , subq_1.archived_at__extract_year AS archived_at__extract_year - , subq_1.archived_at__extract_quarter AS archived_at__extract_quarter - , subq_1.archived_at__extract_month AS archived_at__extract_month - , subq_1.archived_at__extract_day AS archived_at__extract_day - , subq_1.archived_at__extract_dow AS archived_at__extract_dow - , subq_1.archived_at__extract_doy AS archived_at__extract_doy - , subq_1.user__ds__day AS user__ds__day - , subq_1.user__ds__week AS user__ds__week - , subq_1.user__ds__month AS user__ds__month - , subq_1.user__ds__quarter AS user__ds__quarter - , subq_1.user__ds__year AS user__ds__year - , subq_1.user__ds__extract_year AS user__ds__extract_year - , subq_1.user__ds__extract_quarter AS user__ds__extract_quarter - , subq_1.user__ds__extract_month AS user__ds__extract_month - , subq_1.user__ds__extract_day AS user__ds__extract_day - , subq_1.user__ds__extract_dow AS user__ds__extract_dow - , subq_1.user__ds__extract_doy AS user__ds__extract_doy - , subq_1.user__created_at__day AS user__created_at__day - , subq_1.user__created_at__week AS user__created_at__week - , subq_1.user__created_at__month AS user__created_at__month - , subq_1.user__created_at__quarter AS user__created_at__quarter - , subq_1.user__created_at__year AS user__created_at__year - , subq_1.user__created_at__extract_year AS user__created_at__extract_year - , subq_1.user__created_at__extract_quarter AS user__created_at__extract_quarter - , subq_1.user__created_at__extract_month AS user__created_at__extract_month - , subq_1.user__created_at__extract_day AS user__created_at__extract_day - , subq_1.user__created_at__extract_dow AS user__created_at__extract_dow - , subq_1.user__created_at__extract_doy AS user__created_at__extract_doy - , subq_1.user__ds_partitioned__day AS user__ds_partitioned__day - , subq_1.user__ds_partitioned__week AS user__ds_partitioned__week - , subq_1.user__ds_partitioned__month AS user__ds_partitioned__month - , subq_1.user__ds_partitioned__quarter AS user__ds_partitioned__quarter - , subq_1.user__ds_partitioned__year AS user__ds_partitioned__year - , subq_1.user__ds_partitioned__extract_year AS user__ds_partitioned__extract_year - , subq_1.user__ds_partitioned__extract_quarter AS user__ds_partitioned__extract_quarter - , subq_1.user__ds_partitioned__extract_month AS user__ds_partitioned__extract_month - , subq_1.user__ds_partitioned__extract_day AS user__ds_partitioned__extract_day - , subq_1.user__ds_partitioned__extract_dow AS user__ds_partitioned__extract_dow - , subq_1.user__ds_partitioned__extract_doy AS user__ds_partitioned__extract_doy - , subq_1.user__last_profile_edit_ts__millisecond AS user__last_profile_edit_ts__millisecond - , subq_1.user__last_profile_edit_ts__second AS user__last_profile_edit_ts__second - , subq_1.user__last_profile_edit_ts__minute AS user__last_profile_edit_ts__minute - , subq_1.user__last_profile_edit_ts__hour AS user__last_profile_edit_ts__hour - , subq_1.user__last_profile_edit_ts__day AS user__last_profile_edit_ts__day - , subq_1.user__last_profile_edit_ts__week AS user__last_profile_edit_ts__week - , subq_1.user__last_profile_edit_ts__month AS user__last_profile_edit_ts__month - , subq_1.user__last_profile_edit_ts__quarter AS user__last_profile_edit_ts__quarter - , subq_1.user__last_profile_edit_ts__year AS user__last_profile_edit_ts__year - , subq_1.user__last_profile_edit_ts__extract_year AS user__last_profile_edit_ts__extract_year - , subq_1.user__last_profile_edit_ts__extract_quarter AS user__last_profile_edit_ts__extract_quarter - , subq_1.user__last_profile_edit_ts__extract_month AS user__last_profile_edit_ts__extract_month - , subq_1.user__last_profile_edit_ts__extract_day AS user__last_profile_edit_ts__extract_day - , subq_1.user__last_profile_edit_ts__extract_dow AS user__last_profile_edit_ts__extract_dow - , subq_1.user__last_profile_edit_ts__extract_doy AS user__last_profile_edit_ts__extract_doy - , subq_1.user__bio_added_ts__second AS user__bio_added_ts__second - , subq_1.user__bio_added_ts__minute AS user__bio_added_ts__minute - , subq_1.user__bio_added_ts__hour AS user__bio_added_ts__hour - , subq_1.user__bio_added_ts__day AS user__bio_added_ts__day - , subq_1.user__bio_added_ts__week AS user__bio_added_ts__week - , subq_1.user__bio_added_ts__month AS user__bio_added_ts__month - , subq_1.user__bio_added_ts__quarter AS user__bio_added_ts__quarter - , subq_1.user__bio_added_ts__year AS user__bio_added_ts__year - , subq_1.user__bio_added_ts__extract_year AS user__bio_added_ts__extract_year - , subq_1.user__bio_added_ts__extract_quarter AS user__bio_added_ts__extract_quarter - , subq_1.user__bio_added_ts__extract_month AS user__bio_added_ts__extract_month - , subq_1.user__bio_added_ts__extract_day AS user__bio_added_ts__extract_day - , subq_1.user__bio_added_ts__extract_dow AS user__bio_added_ts__extract_dow - , subq_1.user__bio_added_ts__extract_doy AS user__bio_added_ts__extract_doy - , subq_1.user__last_login_ts__minute AS user__last_login_ts__minute - , subq_1.user__last_login_ts__hour AS user__last_login_ts__hour - , subq_1.user__last_login_ts__day AS user__last_login_ts__day - , subq_1.user__last_login_ts__week AS user__last_login_ts__week - , subq_1.user__last_login_ts__month AS user__last_login_ts__month - , subq_1.user__last_login_ts__quarter AS user__last_login_ts__quarter - , subq_1.user__last_login_ts__year AS user__last_login_ts__year - , subq_1.user__last_login_ts__extract_year AS user__last_login_ts__extract_year - , subq_1.user__last_login_ts__extract_quarter AS user__last_login_ts__extract_quarter - , subq_1.user__last_login_ts__extract_month AS user__last_login_ts__extract_month - , subq_1.user__last_login_ts__extract_day AS user__last_login_ts__extract_day - , subq_1.user__last_login_ts__extract_dow AS user__last_login_ts__extract_dow - , subq_1.user__last_login_ts__extract_doy AS user__last_login_ts__extract_doy - , subq_1.user__archived_at__hour AS user__archived_at__hour - , subq_1.user__archived_at__day AS user__archived_at__day - , subq_1.user__archived_at__week AS user__archived_at__week - , subq_1.user__archived_at__month AS user__archived_at__month - , subq_1.user__archived_at__quarter AS user__archived_at__quarter - , subq_1.user__archived_at__year AS user__archived_at__year - , subq_1.user__archived_at__extract_year AS user__archived_at__extract_year - , subq_1.user__archived_at__extract_quarter AS user__archived_at__extract_quarter - , subq_1.user__archived_at__extract_month AS user__archived_at__extract_month - , subq_1.user__archived_at__extract_day AS user__archived_at__extract_day - , subq_1.user__archived_at__extract_dow AS user__archived_at__extract_dow - , subq_1.user__archived_at__extract_doy AS user__archived_at__extract_doy - , subq_1.metric_time__day AS metric_time__day - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_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 + subq_3.ts AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'archived_at' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.created_at__day + , subq_0.created_at__week + , subq_0.created_at__month + , subq_0.created_at__quarter + , subq_0.created_at__year + , subq_0.created_at__extract_year + , subq_0.created_at__extract_quarter + , subq_0.created_at__extract_month + , subq_0.created_at__extract_day + , subq_0.created_at__extract_dow + , subq_0.created_at__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.last_profile_edit_ts__millisecond + , subq_0.last_profile_edit_ts__second + , subq_0.last_profile_edit_ts__minute + , subq_0.last_profile_edit_ts__hour + , subq_0.last_profile_edit_ts__day + , subq_0.last_profile_edit_ts__week + , subq_0.last_profile_edit_ts__month + , subq_0.last_profile_edit_ts__quarter + , subq_0.last_profile_edit_ts__year + , subq_0.last_profile_edit_ts__extract_year + , subq_0.last_profile_edit_ts__extract_quarter + , subq_0.last_profile_edit_ts__extract_month + , subq_0.last_profile_edit_ts__extract_day + , subq_0.last_profile_edit_ts__extract_dow + , subq_0.last_profile_edit_ts__extract_doy + , subq_0.bio_added_ts__second + , subq_0.bio_added_ts__minute + , subq_0.bio_added_ts__hour + , subq_0.bio_added_ts__day + , subq_0.bio_added_ts__week + , subq_0.bio_added_ts__month + , subq_0.bio_added_ts__quarter + , subq_0.bio_added_ts__year + , subq_0.bio_added_ts__extract_year + , subq_0.bio_added_ts__extract_quarter + , subq_0.bio_added_ts__extract_month + , subq_0.bio_added_ts__extract_day + , subq_0.bio_added_ts__extract_dow + , subq_0.bio_added_ts__extract_doy + , subq_0.last_login_ts__minute + , subq_0.last_login_ts__hour + , subq_0.last_login_ts__day + , subq_0.last_login_ts__week + , subq_0.last_login_ts__month + , subq_0.last_login_ts__quarter + , subq_0.last_login_ts__year + , subq_0.last_login_ts__extract_year + , subq_0.last_login_ts__extract_quarter + , subq_0.last_login_ts__extract_month + , subq_0.last_login_ts__extract_day + , subq_0.last_login_ts__extract_dow + , subq_0.last_login_ts__extract_doy + , subq_0.archived_at__hour + , subq_0.archived_at__day + , subq_0.archived_at__week + , subq_0.archived_at__month + , subq_0.archived_at__quarter + , subq_0.archived_at__year + , subq_0.archived_at__extract_year + , subq_0.archived_at__extract_quarter + , subq_0.archived_at__extract_month + , subq_0.archived_at__extract_day + , subq_0.archived_at__extract_dow + , subq_0.archived_at__extract_doy + , subq_0.user__ds__day + , subq_0.user__ds__week + , subq_0.user__ds__month + , subq_0.user__ds__quarter + , subq_0.user__ds__year + , subq_0.user__ds__extract_year + , subq_0.user__ds__extract_quarter + , subq_0.user__ds__extract_month + , subq_0.user__ds__extract_day + , subq_0.user__ds__extract_dow + , subq_0.user__ds__extract_doy + , subq_0.user__created_at__day + , subq_0.user__created_at__week + , subq_0.user__created_at__month + , subq_0.user__created_at__quarter + , subq_0.user__created_at__year + , subq_0.user__created_at__extract_year + , subq_0.user__created_at__extract_quarter + , subq_0.user__created_at__extract_month + , subq_0.user__created_at__extract_day + , subq_0.user__created_at__extract_dow + , subq_0.user__created_at__extract_doy + , subq_0.user__ds_partitioned__day + , subq_0.user__ds_partitioned__week + , subq_0.user__ds_partitioned__month + , subq_0.user__ds_partitioned__quarter + , subq_0.user__ds_partitioned__year + , subq_0.user__ds_partitioned__extract_year + , subq_0.user__ds_partitioned__extract_quarter + , subq_0.user__ds_partitioned__extract_month + , subq_0.user__ds_partitioned__extract_day + , subq_0.user__ds_partitioned__extract_dow + , subq_0.user__ds_partitioned__extract_doy + , subq_0.user__last_profile_edit_ts__millisecond + , subq_0.user__last_profile_edit_ts__second + , subq_0.user__last_profile_edit_ts__minute + , subq_0.user__last_profile_edit_ts__hour + , subq_0.user__last_profile_edit_ts__day + , subq_0.user__last_profile_edit_ts__week + , subq_0.user__last_profile_edit_ts__month + , subq_0.user__last_profile_edit_ts__quarter + , subq_0.user__last_profile_edit_ts__year + , subq_0.user__last_profile_edit_ts__extract_year + , subq_0.user__last_profile_edit_ts__extract_quarter + , subq_0.user__last_profile_edit_ts__extract_month + , subq_0.user__last_profile_edit_ts__extract_day + , subq_0.user__last_profile_edit_ts__extract_dow + , subq_0.user__last_profile_edit_ts__extract_doy + , subq_0.user__bio_added_ts__second + , subq_0.user__bio_added_ts__minute + , subq_0.user__bio_added_ts__hour + , subq_0.user__bio_added_ts__day + , subq_0.user__bio_added_ts__week + , subq_0.user__bio_added_ts__month + , subq_0.user__bio_added_ts__quarter + , subq_0.user__bio_added_ts__year + , subq_0.user__bio_added_ts__extract_year + , subq_0.user__bio_added_ts__extract_quarter + , subq_0.user__bio_added_ts__extract_month + , subq_0.user__bio_added_ts__extract_day + , subq_0.user__bio_added_ts__extract_dow + , subq_0.user__bio_added_ts__extract_doy + , subq_0.user__last_login_ts__minute + , subq_0.user__last_login_ts__hour + , subq_0.user__last_login_ts__day + , subq_0.user__last_login_ts__week + , subq_0.user__last_login_ts__month + , subq_0.user__last_login_ts__quarter + , subq_0.user__last_login_ts__year + , subq_0.user__last_login_ts__extract_year + , subq_0.user__last_login_ts__extract_quarter + , subq_0.user__last_login_ts__extract_month + , subq_0.user__last_login_ts__extract_day + , subq_0.user__last_login_ts__extract_dow + , subq_0.user__last_login_ts__extract_doy + , subq_0.user__archived_at__hour + , subq_0.user__archived_at__day + , subq_0.user__archived_at__week + , subq_0.user__archived_at__month + , subq_0.user__archived_at__quarter + , subq_0.user__archived_at__year + , subq_0.user__archived_at__extract_year + , subq_0.user__archived_at__extract_quarter + , subq_0.user__archived_at__extract_month + , subq_0.user__archived_at__extract_day + , subq_0.user__archived_at__extract_dow + , subq_0.user__archived_at__extract_doy + , subq_0.archived_at__hour AS metric_time__hour + , subq_0.archived_at__day AS metric_time__day + , subq_0.archived_at__week AS metric_time__week + , subq_0.archived_at__month AS metric_time__month + , subq_0.archived_at__quarter AS metric_time__quarter + , subq_0.archived_at__year AS metric_time__year + , subq_0.archived_at__extract_year AS metric_time__extract_year + , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter + , subq_0.archived_at__extract_month AS metric_time__extract_month + , subq_0.archived_at__extract_day AS metric_time__extract_day + , subq_0.archived_at__extract_dow AS metric_time__extract_dow + , subq_0.archived_at__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.home_state + , subq_0.user__home_state + , subq_0.archived_users FROM ( - -- Time Spine - SELECT - subq_3.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'archived_at' + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second - , subq_0.bio_added_ts__minute - , subq_0.bio_added_ts__hour - , subq_0.bio_added_ts__day - , subq_0.bio_added_ts__week - , subq_0.bio_added_ts__month - , subq_0.bio_added_ts__quarter - , subq_0.bio_added_ts__year - , subq_0.bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy - , subq_0.last_login_ts__minute - , subq_0.last_login_ts__hour - , subq_0.last_login_ts__day - , subq_0.last_login_ts__week - , subq_0.last_login_ts__month - , subq_0.last_login_ts__quarter - , subq_0.last_login_ts__year - , subq_0.last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month - , subq_0.last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy - , subq_0.archived_at__hour - , subq_0.archived_at__day - , subq_0.archived_at__week - , subq_0.archived_at__month - , subq_0.archived_at__quarter - , subq_0.archived_at__year - , subq_0.archived_at__extract_year - , subq_0.archived_at__extract_quarter - , subq_0.archived_at__extract_month - , subq_0.archived_at__extract_day - , subq_0.archived_at__extract_dow - , subq_0.archived_at__extract_doy - , subq_0.user__ds__day - , subq_0.user__ds__week - , subq_0.user__ds__month - , subq_0.user__ds__quarter - , subq_0.user__ds__year - , subq_0.user__ds__extract_year - , subq_0.user__ds__extract_quarter - , subq_0.user__ds__extract_month - , subq_0.user__ds__extract_day - , subq_0.user__ds__extract_dow - , subq_0.user__ds__extract_doy - , subq_0.user__created_at__day - , subq_0.user__created_at__week - , subq_0.user__created_at__month - , subq_0.user__created_at__quarter - , subq_0.user__created_at__year - , subq_0.user__created_at__extract_year - , subq_0.user__created_at__extract_quarter - , subq_0.user__created_at__extract_month - , subq_0.user__created_at__extract_day - , subq_0.user__created_at__extract_dow - , subq_0.user__created_at__extract_doy - , subq_0.user__ds_partitioned__day - , subq_0.user__ds_partitioned__week - , subq_0.user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day - , subq_0.user__bio_added_ts__week - , subq_0.user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute - , subq_0.user__last_login_ts__hour - , subq_0.user__last_login_ts__day - , subq_0.user__last_login_ts__week - , subq_0.user__last_login_ts__month - , subq_0.user__last_login_ts__quarter - , subq_0.user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour - , subq_0.user__archived_at__day - , subq_0.user__archived_at__week - , subq_0.user__archived_at__month - , subq_0.user__archived_at__quarter - , subq_0.user__archived_at__year - , subq_0.user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month - , subq_0.user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy - , subq_0.archived_at__hour AS metric_time__hour - , subq_0.archived_at__day AS metric_time__day - , subq_0.archived_at__week AS metric_time__week - , subq_0.archived_at__month AS metric_time__month - , subq_0.archived_at__quarter AS metric_time__quarter - , subq_0.archived_at__year AS metric_time__year - , subq_0.archived_at__extract_year AS metric_time__extract_year - , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter - , subq_0.archived_at__extract_month AS metric_time__extract_month - , subq_0.archived_at__extract_day AS metric_time__extract_day - , subq_0.archived_at__extract_dow AS metric_time__extract_dow - , subq_0.archived_at__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.home_state - , subq_0.user__home_state - , subq_0.archived_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - ) subq_1 - ON - ( - subq_1.metric_time__hour <= subq_2.metric_time__hour - ) AND ( - subq_1.metric_time__hour > subq_2.metric_time__hour - INTERVAL 3 hour - ) - ) subq_4 - ) subq_5 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_0 + ) subq_1 + ON + ( + subq_1.metric_time__hour <= subq_2.metric_time__hour + ) AND ( + subq_1.metric_time__hour > subq_2.metric_time__hour - INTERVAL 3 hour + ) + ) subq_4 GROUP BY - subq_5.metric_time__hour -) subq_6 + subq_4.metric_time__hour +) subq_5 diff --git a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0_optimized.sql index f031751858..737cf00d72 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_cumulative_window_metric__plan0_optimized.sql @@ -3,9 +3,9 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_10.ts AS metric_time__hour - , SUM(subq_8.archived_users) AS subdaily_cumulative_window_metric -FROM ***************************.mf_time_spine_hour subq_10 + subq_9.ts AS metric_time__hour + , SUM(subq_7.archived_users) AS subdaily_cumulative_window_metric +FROM ***************************.mf_time_spine_hour subq_9 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -13,12 +13,12 @@ INNER JOIN ( DATE_TRUNC('hour', archived_at) AS metric_time__hour , 1 AS archived_users FROM ***************************.dim_users users_ds_source_src_28000 -) subq_8 +) subq_7 ON ( - subq_8.metric_time__hour <= subq_10.ts + subq_7.metric_time__hour <= subq_9.ts ) AND ( - subq_8.metric_time__hour > subq_10.ts - INTERVAL 3 hour + subq_7.metric_time__hour > subq_9.ts - INTERVAL 3 hour ) GROUP BY - subq_10.ts + subq_9.ts 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 fe488e80ff..29f64b2730 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 @@ -1,410 +1,217 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_join_to_time_spine_metric + subq_5.metric_time__hour + , subq_5.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_3.archived_users AS archived_users + subq_3.metric_time__hour AS metric_time__hour + , subq_2.archived_users AS archived_users FROM ( -- Time Spine SELECT - subq_5.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_5 - ) subq_4 + subq_4.ts AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_4 + ) subq_3 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_2.metric_time__hour - , SUM(subq_2.archived_users) AS archived_users + subq_1.metric_time__hour + , SUM(subq_1.archived_users) AS archived_users FROM ( + -- Metric Time Dimension 'archived_at' -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_1.metric_time__hour - , subq_1.archived_users + subq_0.archived_at__hour AS metric_time__hour + , subq_0.archived_users FROM ( - -- Metric Time Dimension 'archived_at' + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second - , subq_0.bio_added_ts__minute - , subq_0.bio_added_ts__hour - , subq_0.bio_added_ts__day - , subq_0.bio_added_ts__week - , subq_0.bio_added_ts__month - , subq_0.bio_added_ts__quarter - , subq_0.bio_added_ts__year - , subq_0.bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy - , subq_0.last_login_ts__minute - , subq_0.last_login_ts__hour - , subq_0.last_login_ts__day - , subq_0.last_login_ts__week - , subq_0.last_login_ts__month - , subq_0.last_login_ts__quarter - , subq_0.last_login_ts__year - , subq_0.last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month - , subq_0.last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy - , subq_0.archived_at__hour - , subq_0.archived_at__day - , subq_0.archived_at__week - , subq_0.archived_at__month - , subq_0.archived_at__quarter - , subq_0.archived_at__year - , subq_0.archived_at__extract_year - , subq_0.archived_at__extract_quarter - , subq_0.archived_at__extract_month - , subq_0.archived_at__extract_day - , subq_0.archived_at__extract_dow - , subq_0.archived_at__extract_doy - , subq_0.user__ds__day - , subq_0.user__ds__week - , subq_0.user__ds__month - , subq_0.user__ds__quarter - , subq_0.user__ds__year - , subq_0.user__ds__extract_year - , subq_0.user__ds__extract_quarter - , subq_0.user__ds__extract_month - , subq_0.user__ds__extract_day - , subq_0.user__ds__extract_dow - , subq_0.user__ds__extract_doy - , subq_0.user__created_at__day - , subq_0.user__created_at__week - , subq_0.user__created_at__month - , subq_0.user__created_at__quarter - , subq_0.user__created_at__year - , subq_0.user__created_at__extract_year - , subq_0.user__created_at__extract_quarter - , subq_0.user__created_at__extract_month - , subq_0.user__created_at__extract_day - , subq_0.user__created_at__extract_dow - , subq_0.user__created_at__extract_doy - , subq_0.user__ds_partitioned__day - , subq_0.user__ds_partitioned__week - , subq_0.user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day - , subq_0.user__bio_added_ts__week - , subq_0.user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute - , subq_0.user__last_login_ts__hour - , subq_0.user__last_login_ts__day - , subq_0.user__last_login_ts__week - , subq_0.user__last_login_ts__month - , subq_0.user__last_login_ts__quarter - , subq_0.user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour - , subq_0.user__archived_at__day - , subq_0.user__archived_at__week - , subq_0.user__archived_at__month - , subq_0.user__archived_at__quarter - , subq_0.user__archived_at__year - , subq_0.user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month - , subq_0.user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy - , subq_0.archived_at__hour AS metric_time__hour - , subq_0.archived_at__day AS metric_time__day - , subq_0.archived_at__week AS metric_time__week - , subq_0.archived_at__month AS metric_time__month - , subq_0.archived_at__quarter AS metric_time__quarter - , subq_0.archived_at__year AS metric_time__year - , subq_0.archived_at__extract_year AS metric_time__extract_year - , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter - , subq_0.archived_at__extract_month AS metric_time__extract_month - , subq_0.archived_at__extract_day AS metric_time__extract_day - , subq_0.archived_at__extract_dow AS metric_time__extract_dow - , subq_0.archived_at__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.home_state - , subq_0.user__home_state - , subq_0.archived_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.metric_time__hour - ) subq_3 + subq_1.metric_time__hour + ) subq_2 ON - subq_4.metric_time__hour = subq_3.metric_time__hour -) subq_6 + subq_3.metric_time__hour = subq_2.metric_time__hour +) subq_5 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 44763c6b6e..bed696d4fe 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 @@ -1,9 +1,9 @@ -- 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 + subq_10.ts AS metric_time__hour + , subq_8.archived_users AS subdaily_join_to_time_spine_metric +FROM ***************************.mf_time_spine_hour subq_10 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -17,9 +17,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_7 GROUP BY metric_time__hour -) subq_10 +) subq_8 ON - subq_12.ts = subq_10.metric_time__hour + subq_10.ts = subq_8.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 fe488e80ff..29f64b2730 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 @@ -1,410 +1,217 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__hour - , subq_6.archived_users AS subdaily_join_to_time_spine_metric + subq_5.metric_time__hour + , subq_5.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_3.archived_users AS archived_users + subq_3.metric_time__hour AS metric_time__hour + , subq_2.archived_users AS archived_users FROM ( -- Time Spine SELECT - subq_5.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_5 - ) subq_4 + subq_4.ts AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_4 + ) subq_3 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_2.metric_time__hour - , SUM(subq_2.archived_users) AS archived_users + subq_1.metric_time__hour + , SUM(subq_1.archived_users) AS archived_users FROM ( + -- Metric Time Dimension 'archived_at' -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_1.metric_time__hour - , subq_1.archived_users + subq_0.archived_at__hour AS metric_time__hour + , subq_0.archived_users FROM ( - -- Metric Time Dimension 'archived_at' + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second - , subq_0.bio_added_ts__minute - , subq_0.bio_added_ts__hour - , subq_0.bio_added_ts__day - , subq_0.bio_added_ts__week - , subq_0.bio_added_ts__month - , subq_0.bio_added_ts__quarter - , subq_0.bio_added_ts__year - , subq_0.bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy - , subq_0.last_login_ts__minute - , subq_0.last_login_ts__hour - , subq_0.last_login_ts__day - , subq_0.last_login_ts__week - , subq_0.last_login_ts__month - , subq_0.last_login_ts__quarter - , subq_0.last_login_ts__year - , subq_0.last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month - , subq_0.last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy - , subq_0.archived_at__hour - , subq_0.archived_at__day - , subq_0.archived_at__week - , subq_0.archived_at__month - , subq_0.archived_at__quarter - , subq_0.archived_at__year - , subq_0.archived_at__extract_year - , subq_0.archived_at__extract_quarter - , subq_0.archived_at__extract_month - , subq_0.archived_at__extract_day - , subq_0.archived_at__extract_dow - , subq_0.archived_at__extract_doy - , subq_0.user__ds__day - , subq_0.user__ds__week - , subq_0.user__ds__month - , subq_0.user__ds__quarter - , subq_0.user__ds__year - , subq_0.user__ds__extract_year - , subq_0.user__ds__extract_quarter - , subq_0.user__ds__extract_month - , subq_0.user__ds__extract_day - , subq_0.user__ds__extract_dow - , subq_0.user__ds__extract_doy - , subq_0.user__created_at__day - , subq_0.user__created_at__week - , subq_0.user__created_at__month - , subq_0.user__created_at__quarter - , subq_0.user__created_at__year - , subq_0.user__created_at__extract_year - , subq_0.user__created_at__extract_quarter - , subq_0.user__created_at__extract_month - , subq_0.user__created_at__extract_day - , subq_0.user__created_at__extract_dow - , subq_0.user__created_at__extract_doy - , subq_0.user__ds_partitioned__day - , subq_0.user__ds_partitioned__week - , subq_0.user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day - , subq_0.user__bio_added_ts__week - , subq_0.user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute - , subq_0.user__last_login_ts__hour - , subq_0.user__last_login_ts__day - , subq_0.user__last_login_ts__week - , subq_0.user__last_login_ts__month - , subq_0.user__last_login_ts__quarter - , subq_0.user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour - , subq_0.user__archived_at__day - , subq_0.user__archived_at__week - , subq_0.user__archived_at__month - , subq_0.user__archived_at__quarter - , subq_0.user__archived_at__year - , subq_0.user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month - , subq_0.user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy - , subq_0.archived_at__hour AS metric_time__hour - , subq_0.archived_at__day AS metric_time__day - , subq_0.archived_at__week AS metric_time__week - , subq_0.archived_at__month AS metric_time__month - , subq_0.archived_at__quarter AS metric_time__quarter - , subq_0.archived_at__year AS metric_time__year - , subq_0.archived_at__extract_year AS metric_time__extract_year - , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter - , subq_0.archived_at__extract_month AS metric_time__extract_month - , subq_0.archived_at__extract_day AS metric_time__extract_day - , subq_0.archived_at__extract_dow AS metric_time__extract_dow - , subq_0.archived_at__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.home_state - , subq_0.user__home_state - , subq_0.archived_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_0 + ) subq_1 GROUP BY - subq_2.metric_time__hour - ) subq_3 + subq_1.metric_time__hour + ) subq_2 ON - subq_4.metric_time__hour = subq_3.metric_time__hour -) subq_6 + subq_3.metric_time__hour = subq_2.metric_time__hour +) subq_5 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 44763c6b6e..bed696d4fe 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 @@ -1,9 +1,9 @@ -- 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 + subq_10.ts AS metric_time__hour + , subq_8.archived_users AS subdaily_join_to_time_spine_metric +FROM ***************************.mf_time_spine_hour subq_10 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -17,9 +17,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_7 GROUP BY metric_time__hour -) subq_10 +) subq_8 ON - subq_12.ts = subq_10.metric_time__hour + subq_10.ts = subq_8.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 d30be670b4..d02e0c27b9 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 @@ -1,604 +1,411 @@ -- Compute Metrics via Expressions SELECT - subq_7.metric_time__hour + subq_6.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_5.metric_time__hour + , subq_5.archived_users FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_4.metric_time__hour + , SUM(subq_4.archived_users) AS archived_users FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_2.metric_time__hour AS metric_time__hour + , subq_1.archived_users AS archived_users FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__hour AS metric_time__hour - , DATE_TRUNC('day', subq_2.metric_time__hour) AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__hour) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__hour) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__hour) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__hour) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__hour) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__hour) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__hour) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__hour) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__hour) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__hour) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.created_at__day AS created_at__day - , subq_1.created_at__week AS created_at__week - , subq_1.created_at__month AS created_at__month - , subq_1.created_at__quarter AS created_at__quarter - , subq_1.created_at__year AS created_at__year - , subq_1.created_at__extract_year AS created_at__extract_year - , subq_1.created_at__extract_quarter AS created_at__extract_quarter - , subq_1.created_at__extract_month AS created_at__extract_month - , subq_1.created_at__extract_day AS created_at__extract_day - , subq_1.created_at__extract_dow AS created_at__extract_dow - , subq_1.created_at__extract_doy AS created_at__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.last_profile_edit_ts__millisecond AS last_profile_edit_ts__millisecond - , subq_1.last_profile_edit_ts__second AS last_profile_edit_ts__second - , subq_1.last_profile_edit_ts__minute AS last_profile_edit_ts__minute - , subq_1.last_profile_edit_ts__hour AS last_profile_edit_ts__hour - , subq_1.last_profile_edit_ts__day AS last_profile_edit_ts__day - , subq_1.last_profile_edit_ts__week AS last_profile_edit_ts__week - , subq_1.last_profile_edit_ts__month AS last_profile_edit_ts__month - , subq_1.last_profile_edit_ts__quarter AS last_profile_edit_ts__quarter - , subq_1.last_profile_edit_ts__year AS last_profile_edit_ts__year - , subq_1.last_profile_edit_ts__extract_year AS last_profile_edit_ts__extract_year - , subq_1.last_profile_edit_ts__extract_quarter AS last_profile_edit_ts__extract_quarter - , subq_1.last_profile_edit_ts__extract_month AS last_profile_edit_ts__extract_month - , subq_1.last_profile_edit_ts__extract_day AS last_profile_edit_ts__extract_day - , subq_1.last_profile_edit_ts__extract_dow AS last_profile_edit_ts__extract_dow - , subq_1.last_profile_edit_ts__extract_doy AS last_profile_edit_ts__extract_doy - , subq_1.bio_added_ts__second AS bio_added_ts__second - , subq_1.bio_added_ts__minute AS bio_added_ts__minute - , subq_1.bio_added_ts__hour AS bio_added_ts__hour - , subq_1.bio_added_ts__day AS bio_added_ts__day - , subq_1.bio_added_ts__week AS bio_added_ts__week - , subq_1.bio_added_ts__month AS bio_added_ts__month - , subq_1.bio_added_ts__quarter AS bio_added_ts__quarter - , subq_1.bio_added_ts__year AS bio_added_ts__year - , subq_1.bio_added_ts__extract_year AS bio_added_ts__extract_year - , subq_1.bio_added_ts__extract_quarter AS bio_added_ts__extract_quarter - , subq_1.bio_added_ts__extract_month AS bio_added_ts__extract_month - , subq_1.bio_added_ts__extract_day AS bio_added_ts__extract_day - , subq_1.bio_added_ts__extract_dow AS bio_added_ts__extract_dow - , subq_1.bio_added_ts__extract_doy AS bio_added_ts__extract_doy - , subq_1.last_login_ts__minute AS last_login_ts__minute - , subq_1.last_login_ts__hour AS last_login_ts__hour - , subq_1.last_login_ts__day AS last_login_ts__day - , subq_1.last_login_ts__week AS last_login_ts__week - , subq_1.last_login_ts__month AS last_login_ts__month - , subq_1.last_login_ts__quarter AS last_login_ts__quarter - , subq_1.last_login_ts__year AS last_login_ts__year - , subq_1.last_login_ts__extract_year AS last_login_ts__extract_year - , subq_1.last_login_ts__extract_quarter AS last_login_ts__extract_quarter - , subq_1.last_login_ts__extract_month AS last_login_ts__extract_month - , subq_1.last_login_ts__extract_day AS last_login_ts__extract_day - , subq_1.last_login_ts__extract_dow AS last_login_ts__extract_dow - , subq_1.last_login_ts__extract_doy AS last_login_ts__extract_doy - , subq_1.archived_at__hour AS archived_at__hour - , subq_1.archived_at__day AS archived_at__day - , subq_1.archived_at__week AS archived_at__week - , subq_1.archived_at__month AS archived_at__month - , subq_1.archived_at__quarter AS archived_at__quarter - , subq_1.archived_at__year AS archived_at__year - , subq_1.archived_at__extract_year AS archived_at__extract_year - , subq_1.archived_at__extract_quarter AS archived_at__extract_quarter - , subq_1.archived_at__extract_month AS archived_at__extract_month - , subq_1.archived_at__extract_day AS archived_at__extract_day - , subq_1.archived_at__extract_dow AS archived_at__extract_dow - , subq_1.archived_at__extract_doy AS archived_at__extract_doy - , subq_1.user__ds__day AS user__ds__day - , subq_1.user__ds__week AS user__ds__week - , subq_1.user__ds__month AS user__ds__month - , subq_1.user__ds__quarter AS user__ds__quarter - , subq_1.user__ds__year AS user__ds__year - , subq_1.user__ds__extract_year AS user__ds__extract_year - , subq_1.user__ds__extract_quarter AS user__ds__extract_quarter - , subq_1.user__ds__extract_month AS user__ds__extract_month - , subq_1.user__ds__extract_day AS user__ds__extract_day - , subq_1.user__ds__extract_dow AS user__ds__extract_dow - , subq_1.user__ds__extract_doy AS user__ds__extract_doy - , subq_1.user__created_at__day AS user__created_at__day - , subq_1.user__created_at__week AS user__created_at__week - , subq_1.user__created_at__month AS user__created_at__month - , subq_1.user__created_at__quarter AS user__created_at__quarter - , subq_1.user__created_at__year AS user__created_at__year - , subq_1.user__created_at__extract_year AS user__created_at__extract_year - , subq_1.user__created_at__extract_quarter AS user__created_at__extract_quarter - , subq_1.user__created_at__extract_month AS user__created_at__extract_month - , subq_1.user__created_at__extract_day AS user__created_at__extract_day - , subq_1.user__created_at__extract_dow AS user__created_at__extract_dow - , subq_1.user__created_at__extract_doy AS user__created_at__extract_doy - , subq_1.user__ds_partitioned__day AS user__ds_partitioned__day - , subq_1.user__ds_partitioned__week AS user__ds_partitioned__week - , subq_1.user__ds_partitioned__month AS user__ds_partitioned__month - , subq_1.user__ds_partitioned__quarter AS user__ds_partitioned__quarter - , subq_1.user__ds_partitioned__year AS user__ds_partitioned__year - , subq_1.user__ds_partitioned__extract_year AS user__ds_partitioned__extract_year - , subq_1.user__ds_partitioned__extract_quarter AS user__ds_partitioned__extract_quarter - , subq_1.user__ds_partitioned__extract_month AS user__ds_partitioned__extract_month - , subq_1.user__ds_partitioned__extract_day AS user__ds_partitioned__extract_day - , subq_1.user__ds_partitioned__extract_dow AS user__ds_partitioned__extract_dow - , subq_1.user__ds_partitioned__extract_doy AS user__ds_partitioned__extract_doy - , subq_1.user__last_profile_edit_ts__millisecond AS user__last_profile_edit_ts__millisecond - , subq_1.user__last_profile_edit_ts__second AS user__last_profile_edit_ts__second - , subq_1.user__last_profile_edit_ts__minute AS user__last_profile_edit_ts__minute - , subq_1.user__last_profile_edit_ts__hour AS user__last_profile_edit_ts__hour - , subq_1.user__last_profile_edit_ts__day AS user__last_profile_edit_ts__day - , subq_1.user__last_profile_edit_ts__week AS user__last_profile_edit_ts__week - , subq_1.user__last_profile_edit_ts__month AS user__last_profile_edit_ts__month - , subq_1.user__last_profile_edit_ts__quarter AS user__last_profile_edit_ts__quarter - , subq_1.user__last_profile_edit_ts__year AS user__last_profile_edit_ts__year - , subq_1.user__last_profile_edit_ts__extract_year AS user__last_profile_edit_ts__extract_year - , subq_1.user__last_profile_edit_ts__extract_quarter AS user__last_profile_edit_ts__extract_quarter - , subq_1.user__last_profile_edit_ts__extract_month AS user__last_profile_edit_ts__extract_month - , subq_1.user__last_profile_edit_ts__extract_day AS user__last_profile_edit_ts__extract_day - , subq_1.user__last_profile_edit_ts__extract_dow AS user__last_profile_edit_ts__extract_dow - , subq_1.user__last_profile_edit_ts__extract_doy AS user__last_profile_edit_ts__extract_doy - , subq_1.user__bio_added_ts__second AS user__bio_added_ts__second - , subq_1.user__bio_added_ts__minute AS user__bio_added_ts__minute - , subq_1.user__bio_added_ts__hour AS user__bio_added_ts__hour - , subq_1.user__bio_added_ts__day AS user__bio_added_ts__day - , subq_1.user__bio_added_ts__week AS user__bio_added_ts__week - , subq_1.user__bio_added_ts__month AS user__bio_added_ts__month - , subq_1.user__bio_added_ts__quarter AS user__bio_added_ts__quarter - , subq_1.user__bio_added_ts__year AS user__bio_added_ts__year - , subq_1.user__bio_added_ts__extract_year AS user__bio_added_ts__extract_year - , subq_1.user__bio_added_ts__extract_quarter AS user__bio_added_ts__extract_quarter - , subq_1.user__bio_added_ts__extract_month AS user__bio_added_ts__extract_month - , subq_1.user__bio_added_ts__extract_day AS user__bio_added_ts__extract_day - , subq_1.user__bio_added_ts__extract_dow AS user__bio_added_ts__extract_dow - , subq_1.user__bio_added_ts__extract_doy AS user__bio_added_ts__extract_doy - , subq_1.user__last_login_ts__minute AS user__last_login_ts__minute - , subq_1.user__last_login_ts__hour AS user__last_login_ts__hour - , subq_1.user__last_login_ts__day AS user__last_login_ts__day - , subq_1.user__last_login_ts__week AS user__last_login_ts__week - , subq_1.user__last_login_ts__month AS user__last_login_ts__month - , subq_1.user__last_login_ts__quarter AS user__last_login_ts__quarter - , subq_1.user__last_login_ts__year AS user__last_login_ts__year - , subq_1.user__last_login_ts__extract_year AS user__last_login_ts__extract_year - , subq_1.user__last_login_ts__extract_quarter AS user__last_login_ts__extract_quarter - , subq_1.user__last_login_ts__extract_month AS user__last_login_ts__extract_month - , subq_1.user__last_login_ts__extract_day AS user__last_login_ts__extract_day - , subq_1.user__last_login_ts__extract_dow AS user__last_login_ts__extract_dow - , subq_1.user__last_login_ts__extract_doy AS user__last_login_ts__extract_doy - , subq_1.user__archived_at__hour AS user__archived_at__hour - , subq_1.user__archived_at__day AS user__archived_at__day - , subq_1.user__archived_at__week AS user__archived_at__week - , subq_1.user__archived_at__month AS user__archived_at__month - , subq_1.user__archived_at__quarter AS user__archived_at__quarter - , subq_1.user__archived_at__year AS user__archived_at__year - , subq_1.user__archived_at__extract_year AS user__archived_at__extract_year - , subq_1.user__archived_at__extract_quarter AS user__archived_at__extract_quarter - , subq_1.user__archived_at__extract_month AS user__archived_at__extract_month - , subq_1.user__archived_at__extract_day AS user__archived_at__extract_day - , subq_1.user__archived_at__extract_dow AS user__archived_at__extract_dow - , subq_1.user__archived_at__extract_doy AS user__archived_at__extract_doy - , 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 + subq_3.ts AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'archived_at' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.created_at__day + , subq_0.created_at__week + , subq_0.created_at__month + , subq_0.created_at__quarter + , subq_0.created_at__year + , subq_0.created_at__extract_year + , subq_0.created_at__extract_quarter + , subq_0.created_at__extract_month + , subq_0.created_at__extract_day + , subq_0.created_at__extract_dow + , subq_0.created_at__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.last_profile_edit_ts__millisecond + , subq_0.last_profile_edit_ts__second + , subq_0.last_profile_edit_ts__minute + , subq_0.last_profile_edit_ts__hour + , subq_0.last_profile_edit_ts__day + , subq_0.last_profile_edit_ts__week + , subq_0.last_profile_edit_ts__month + , subq_0.last_profile_edit_ts__quarter + , subq_0.last_profile_edit_ts__year + , subq_0.last_profile_edit_ts__extract_year + , subq_0.last_profile_edit_ts__extract_quarter + , subq_0.last_profile_edit_ts__extract_month + , subq_0.last_profile_edit_ts__extract_day + , subq_0.last_profile_edit_ts__extract_dow + , subq_0.last_profile_edit_ts__extract_doy + , subq_0.bio_added_ts__second + , subq_0.bio_added_ts__minute + , subq_0.bio_added_ts__hour + , subq_0.bio_added_ts__day + , subq_0.bio_added_ts__week + , subq_0.bio_added_ts__month + , subq_0.bio_added_ts__quarter + , subq_0.bio_added_ts__year + , subq_0.bio_added_ts__extract_year + , subq_0.bio_added_ts__extract_quarter + , subq_0.bio_added_ts__extract_month + , subq_0.bio_added_ts__extract_day + , subq_0.bio_added_ts__extract_dow + , subq_0.bio_added_ts__extract_doy + , subq_0.last_login_ts__minute + , subq_0.last_login_ts__hour + , subq_0.last_login_ts__day + , subq_0.last_login_ts__week + , subq_0.last_login_ts__month + , subq_0.last_login_ts__quarter + , subq_0.last_login_ts__year + , subq_0.last_login_ts__extract_year + , subq_0.last_login_ts__extract_quarter + , subq_0.last_login_ts__extract_month + , subq_0.last_login_ts__extract_day + , subq_0.last_login_ts__extract_dow + , subq_0.last_login_ts__extract_doy + , subq_0.archived_at__hour + , subq_0.archived_at__day + , subq_0.archived_at__week + , subq_0.archived_at__month + , subq_0.archived_at__quarter + , subq_0.archived_at__year + , subq_0.archived_at__extract_year + , subq_0.archived_at__extract_quarter + , subq_0.archived_at__extract_month + , subq_0.archived_at__extract_day + , subq_0.archived_at__extract_dow + , subq_0.archived_at__extract_doy + , subq_0.user__ds__day + , subq_0.user__ds__week + , subq_0.user__ds__month + , subq_0.user__ds__quarter + , subq_0.user__ds__year + , subq_0.user__ds__extract_year + , subq_0.user__ds__extract_quarter + , subq_0.user__ds__extract_month + , subq_0.user__ds__extract_day + , subq_0.user__ds__extract_dow + , subq_0.user__ds__extract_doy + , subq_0.user__created_at__day + , subq_0.user__created_at__week + , subq_0.user__created_at__month + , subq_0.user__created_at__quarter + , subq_0.user__created_at__year + , subq_0.user__created_at__extract_year + , subq_0.user__created_at__extract_quarter + , subq_0.user__created_at__extract_month + , subq_0.user__created_at__extract_day + , subq_0.user__created_at__extract_dow + , subq_0.user__created_at__extract_doy + , subq_0.user__ds_partitioned__day + , subq_0.user__ds_partitioned__week + , subq_0.user__ds_partitioned__month + , subq_0.user__ds_partitioned__quarter + , subq_0.user__ds_partitioned__year + , subq_0.user__ds_partitioned__extract_year + , subq_0.user__ds_partitioned__extract_quarter + , subq_0.user__ds_partitioned__extract_month + , subq_0.user__ds_partitioned__extract_day + , subq_0.user__ds_partitioned__extract_dow + , subq_0.user__ds_partitioned__extract_doy + , subq_0.user__last_profile_edit_ts__millisecond + , subq_0.user__last_profile_edit_ts__second + , subq_0.user__last_profile_edit_ts__minute + , subq_0.user__last_profile_edit_ts__hour + , subq_0.user__last_profile_edit_ts__day + , subq_0.user__last_profile_edit_ts__week + , subq_0.user__last_profile_edit_ts__month + , subq_0.user__last_profile_edit_ts__quarter + , subq_0.user__last_profile_edit_ts__year + , subq_0.user__last_profile_edit_ts__extract_year + , subq_0.user__last_profile_edit_ts__extract_quarter + , subq_0.user__last_profile_edit_ts__extract_month + , subq_0.user__last_profile_edit_ts__extract_day + , subq_0.user__last_profile_edit_ts__extract_dow + , subq_0.user__last_profile_edit_ts__extract_doy + , subq_0.user__bio_added_ts__second + , subq_0.user__bio_added_ts__minute + , subq_0.user__bio_added_ts__hour + , subq_0.user__bio_added_ts__day + , subq_0.user__bio_added_ts__week + , subq_0.user__bio_added_ts__month + , subq_0.user__bio_added_ts__quarter + , subq_0.user__bio_added_ts__year + , subq_0.user__bio_added_ts__extract_year + , subq_0.user__bio_added_ts__extract_quarter + , subq_0.user__bio_added_ts__extract_month + , subq_0.user__bio_added_ts__extract_day + , subq_0.user__bio_added_ts__extract_dow + , subq_0.user__bio_added_ts__extract_doy + , subq_0.user__last_login_ts__minute + , subq_0.user__last_login_ts__hour + , subq_0.user__last_login_ts__day + , subq_0.user__last_login_ts__week + , subq_0.user__last_login_ts__month + , subq_0.user__last_login_ts__quarter + , subq_0.user__last_login_ts__year + , subq_0.user__last_login_ts__extract_year + , subq_0.user__last_login_ts__extract_quarter + , subq_0.user__last_login_ts__extract_month + , subq_0.user__last_login_ts__extract_day + , subq_0.user__last_login_ts__extract_dow + , subq_0.user__last_login_ts__extract_doy + , subq_0.user__archived_at__hour + , subq_0.user__archived_at__day + , subq_0.user__archived_at__week + , subq_0.user__archived_at__month + , subq_0.user__archived_at__quarter + , subq_0.user__archived_at__year + , subq_0.user__archived_at__extract_year + , subq_0.user__archived_at__extract_quarter + , subq_0.user__archived_at__extract_month + , subq_0.user__archived_at__extract_day + , subq_0.user__archived_at__extract_dow + , subq_0.user__archived_at__extract_doy + , subq_0.archived_at__hour AS metric_time__hour + , subq_0.archived_at__day AS metric_time__day + , subq_0.archived_at__week AS metric_time__week + , subq_0.archived_at__month AS metric_time__month + , subq_0.archived_at__quarter AS metric_time__quarter + , subq_0.archived_at__year AS metric_time__year + , subq_0.archived_at__extract_year AS metric_time__extract_year + , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter + , subq_0.archived_at__extract_month AS metric_time__extract_month + , subq_0.archived_at__extract_day AS metric_time__extract_day + , subq_0.archived_at__extract_dow AS metric_time__extract_dow + , subq_0.archived_at__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.home_state + , subq_0.user__home_state + , subq_0.archived_users FROM ( - -- Time Spine - SELECT - subq_3.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'archived_at' + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second - , subq_0.bio_added_ts__minute - , subq_0.bio_added_ts__hour - , subq_0.bio_added_ts__day - , subq_0.bio_added_ts__week - , subq_0.bio_added_ts__month - , subq_0.bio_added_ts__quarter - , subq_0.bio_added_ts__year - , subq_0.bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy - , subq_0.last_login_ts__minute - , subq_0.last_login_ts__hour - , subq_0.last_login_ts__day - , subq_0.last_login_ts__week - , subq_0.last_login_ts__month - , subq_0.last_login_ts__quarter - , subq_0.last_login_ts__year - , subq_0.last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month - , subq_0.last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy - , subq_0.archived_at__hour - , subq_0.archived_at__day - , subq_0.archived_at__week - , subq_0.archived_at__month - , subq_0.archived_at__quarter - , subq_0.archived_at__year - , subq_0.archived_at__extract_year - , subq_0.archived_at__extract_quarter - , subq_0.archived_at__extract_month - , subq_0.archived_at__extract_day - , subq_0.archived_at__extract_dow - , subq_0.archived_at__extract_doy - , subq_0.user__ds__day - , subq_0.user__ds__week - , subq_0.user__ds__month - , subq_0.user__ds__quarter - , subq_0.user__ds__year - , subq_0.user__ds__extract_year - , subq_0.user__ds__extract_quarter - , subq_0.user__ds__extract_month - , subq_0.user__ds__extract_day - , subq_0.user__ds__extract_dow - , subq_0.user__ds__extract_doy - , subq_0.user__created_at__day - , subq_0.user__created_at__week - , subq_0.user__created_at__month - , subq_0.user__created_at__quarter - , subq_0.user__created_at__year - , subq_0.user__created_at__extract_year - , subq_0.user__created_at__extract_quarter - , subq_0.user__created_at__extract_month - , subq_0.user__created_at__extract_day - , subq_0.user__created_at__extract_dow - , subq_0.user__created_at__extract_doy - , subq_0.user__ds_partitioned__day - , subq_0.user__ds_partitioned__week - , subq_0.user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day - , subq_0.user__bio_added_ts__week - , subq_0.user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute - , subq_0.user__last_login_ts__hour - , subq_0.user__last_login_ts__day - , subq_0.user__last_login_ts__week - , subq_0.user__last_login_ts__month - , subq_0.user__last_login_ts__quarter - , subq_0.user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour - , subq_0.user__archived_at__day - , subq_0.user__archived_at__week - , subq_0.user__archived_at__month - , subq_0.user__archived_at__quarter - , subq_0.user__archived_at__year - , subq_0.user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month - , subq_0.user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy - , subq_0.archived_at__hour AS metric_time__hour - , subq_0.archived_at__day AS metric_time__day - , subq_0.archived_at__week AS metric_time__week - , subq_0.archived_at__month AS metric_time__month - , subq_0.archived_at__quarter AS metric_time__quarter - , subq_0.archived_at__year AS metric_time__year - , subq_0.archived_at__extract_year AS metric_time__extract_year - , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter - , subq_0.archived_at__extract_month AS metric_time__extract_month - , subq_0.archived_at__extract_day AS metric_time__extract_day - , subq_0.archived_at__extract_dow AS metric_time__extract_dow - , subq_0.archived_at__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.home_state - , subq_0.user__home_state - , subq_0.archived_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - ) subq_1 - ON - DATE_TRUNC('hour', subq_2.metric_time__hour) = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_0 + ) subq_1 + ON + DATE_TRUNC('hour', subq_2.metric_time__hour) = subq_1.metric_time__hour + ) subq_4 GROUP BY - subq_5.metric_time__hour - ) subq_6 -) subq_7 + subq_4.metric_time__hour + ) subq_5 +) subq_6 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 2679104380..a3cbaee4e5 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 @@ -8,9 +8,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 + subq_10.ts AS metric_time__hour + , SUM(subq_8.archived_users) AS archived_users + FROM ***************************.mf_time_spine_hour subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -18,9 +18,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_8 ON - DATE_TRUNC('hour', subq_11.ts) = subq_9.metric_time__hour + DATE_TRUNC('hour', subq_10.ts) = subq_8.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + subq_10.ts +) subq_13 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 9a1d976fcd..da3ae0be9e 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 @@ -1,604 +1,411 @@ -- Compute Metrics via Expressions SELECT - subq_7.metric_time__hour + subq_6.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_5.metric_time__hour + , subq_5.archived_users FROM ( -- Aggregate Measures SELECT - subq_5.metric_time__hour - , SUM(subq_5.archived_users) AS archived_users + subq_4.metric_time__hour + , SUM(subq_4.archived_users) AS archived_users FROM ( + -- Join to Time Spine Dataset -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_4.metric_time__hour - , subq_4.archived_users + subq_2.metric_time__hour AS metric_time__hour + , subq_1.archived_users AS archived_users FROM ( - -- Join to Time Spine Dataset + -- Time Spine SELECT - subq_2.metric_time__hour AS metric_time__hour - , DATE_TRUNC('day', subq_2.metric_time__hour) AS metric_time__day - , DATE_TRUNC('week', subq_2.metric_time__hour) AS metric_time__week - , DATE_TRUNC('month', subq_2.metric_time__hour) AS metric_time__month - , DATE_TRUNC('quarter', subq_2.metric_time__hour) AS metric_time__quarter - , DATE_TRUNC('year', subq_2.metric_time__hour) AS metric_time__year - , EXTRACT(year FROM subq_2.metric_time__hour) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_2.metric_time__hour) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_2.metric_time__hour) AS metric_time__extract_month - , EXTRACT(day FROM subq_2.metric_time__hour) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_2.metric_time__hour) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_2.metric_time__hour) AS metric_time__extract_doy - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.created_at__day AS created_at__day - , subq_1.created_at__week AS created_at__week - , subq_1.created_at__month AS created_at__month - , subq_1.created_at__quarter AS created_at__quarter - , subq_1.created_at__year AS created_at__year - , subq_1.created_at__extract_year AS created_at__extract_year - , subq_1.created_at__extract_quarter AS created_at__extract_quarter - , subq_1.created_at__extract_month AS created_at__extract_month - , subq_1.created_at__extract_day AS created_at__extract_day - , subq_1.created_at__extract_dow AS created_at__extract_dow - , subq_1.created_at__extract_doy AS created_at__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.last_profile_edit_ts__millisecond AS last_profile_edit_ts__millisecond - , subq_1.last_profile_edit_ts__second AS last_profile_edit_ts__second - , subq_1.last_profile_edit_ts__minute AS last_profile_edit_ts__minute - , subq_1.last_profile_edit_ts__hour AS last_profile_edit_ts__hour - , subq_1.last_profile_edit_ts__day AS last_profile_edit_ts__day - , subq_1.last_profile_edit_ts__week AS last_profile_edit_ts__week - , subq_1.last_profile_edit_ts__month AS last_profile_edit_ts__month - , subq_1.last_profile_edit_ts__quarter AS last_profile_edit_ts__quarter - , subq_1.last_profile_edit_ts__year AS last_profile_edit_ts__year - , subq_1.last_profile_edit_ts__extract_year AS last_profile_edit_ts__extract_year - , subq_1.last_profile_edit_ts__extract_quarter AS last_profile_edit_ts__extract_quarter - , subq_1.last_profile_edit_ts__extract_month AS last_profile_edit_ts__extract_month - , subq_1.last_profile_edit_ts__extract_day AS last_profile_edit_ts__extract_day - , subq_1.last_profile_edit_ts__extract_dow AS last_profile_edit_ts__extract_dow - , subq_1.last_profile_edit_ts__extract_doy AS last_profile_edit_ts__extract_doy - , subq_1.bio_added_ts__second AS bio_added_ts__second - , subq_1.bio_added_ts__minute AS bio_added_ts__minute - , subq_1.bio_added_ts__hour AS bio_added_ts__hour - , subq_1.bio_added_ts__day AS bio_added_ts__day - , subq_1.bio_added_ts__week AS bio_added_ts__week - , subq_1.bio_added_ts__month AS bio_added_ts__month - , subq_1.bio_added_ts__quarter AS bio_added_ts__quarter - , subq_1.bio_added_ts__year AS bio_added_ts__year - , subq_1.bio_added_ts__extract_year AS bio_added_ts__extract_year - , subq_1.bio_added_ts__extract_quarter AS bio_added_ts__extract_quarter - , subq_1.bio_added_ts__extract_month AS bio_added_ts__extract_month - , subq_1.bio_added_ts__extract_day AS bio_added_ts__extract_day - , subq_1.bio_added_ts__extract_dow AS bio_added_ts__extract_dow - , subq_1.bio_added_ts__extract_doy AS bio_added_ts__extract_doy - , subq_1.last_login_ts__minute AS last_login_ts__minute - , subq_1.last_login_ts__hour AS last_login_ts__hour - , subq_1.last_login_ts__day AS last_login_ts__day - , subq_1.last_login_ts__week AS last_login_ts__week - , subq_1.last_login_ts__month AS last_login_ts__month - , subq_1.last_login_ts__quarter AS last_login_ts__quarter - , subq_1.last_login_ts__year AS last_login_ts__year - , subq_1.last_login_ts__extract_year AS last_login_ts__extract_year - , subq_1.last_login_ts__extract_quarter AS last_login_ts__extract_quarter - , subq_1.last_login_ts__extract_month AS last_login_ts__extract_month - , subq_1.last_login_ts__extract_day AS last_login_ts__extract_day - , subq_1.last_login_ts__extract_dow AS last_login_ts__extract_dow - , subq_1.last_login_ts__extract_doy AS last_login_ts__extract_doy - , subq_1.archived_at__hour AS archived_at__hour - , subq_1.archived_at__day AS archived_at__day - , subq_1.archived_at__week AS archived_at__week - , subq_1.archived_at__month AS archived_at__month - , subq_1.archived_at__quarter AS archived_at__quarter - , subq_1.archived_at__year AS archived_at__year - , subq_1.archived_at__extract_year AS archived_at__extract_year - , subq_1.archived_at__extract_quarter AS archived_at__extract_quarter - , subq_1.archived_at__extract_month AS archived_at__extract_month - , subq_1.archived_at__extract_day AS archived_at__extract_day - , subq_1.archived_at__extract_dow AS archived_at__extract_dow - , subq_1.archived_at__extract_doy AS archived_at__extract_doy - , subq_1.user__ds__day AS user__ds__day - , subq_1.user__ds__week AS user__ds__week - , subq_1.user__ds__month AS user__ds__month - , subq_1.user__ds__quarter AS user__ds__quarter - , subq_1.user__ds__year AS user__ds__year - , subq_1.user__ds__extract_year AS user__ds__extract_year - , subq_1.user__ds__extract_quarter AS user__ds__extract_quarter - , subq_1.user__ds__extract_month AS user__ds__extract_month - , subq_1.user__ds__extract_day AS user__ds__extract_day - , subq_1.user__ds__extract_dow AS user__ds__extract_dow - , subq_1.user__ds__extract_doy AS user__ds__extract_doy - , subq_1.user__created_at__day AS user__created_at__day - , subq_1.user__created_at__week AS user__created_at__week - , subq_1.user__created_at__month AS user__created_at__month - , subq_1.user__created_at__quarter AS user__created_at__quarter - , subq_1.user__created_at__year AS user__created_at__year - , subq_1.user__created_at__extract_year AS user__created_at__extract_year - , subq_1.user__created_at__extract_quarter AS user__created_at__extract_quarter - , subq_1.user__created_at__extract_month AS user__created_at__extract_month - , subq_1.user__created_at__extract_day AS user__created_at__extract_day - , subq_1.user__created_at__extract_dow AS user__created_at__extract_dow - , subq_1.user__created_at__extract_doy AS user__created_at__extract_doy - , subq_1.user__ds_partitioned__day AS user__ds_partitioned__day - , subq_1.user__ds_partitioned__week AS user__ds_partitioned__week - , subq_1.user__ds_partitioned__month AS user__ds_partitioned__month - , subq_1.user__ds_partitioned__quarter AS user__ds_partitioned__quarter - , subq_1.user__ds_partitioned__year AS user__ds_partitioned__year - , subq_1.user__ds_partitioned__extract_year AS user__ds_partitioned__extract_year - , subq_1.user__ds_partitioned__extract_quarter AS user__ds_partitioned__extract_quarter - , subq_1.user__ds_partitioned__extract_month AS user__ds_partitioned__extract_month - , subq_1.user__ds_partitioned__extract_day AS user__ds_partitioned__extract_day - , subq_1.user__ds_partitioned__extract_dow AS user__ds_partitioned__extract_dow - , subq_1.user__ds_partitioned__extract_doy AS user__ds_partitioned__extract_doy - , subq_1.user__last_profile_edit_ts__millisecond AS user__last_profile_edit_ts__millisecond - , subq_1.user__last_profile_edit_ts__second AS user__last_profile_edit_ts__second - , subq_1.user__last_profile_edit_ts__minute AS user__last_profile_edit_ts__minute - , subq_1.user__last_profile_edit_ts__hour AS user__last_profile_edit_ts__hour - , subq_1.user__last_profile_edit_ts__day AS user__last_profile_edit_ts__day - , subq_1.user__last_profile_edit_ts__week AS user__last_profile_edit_ts__week - , subq_1.user__last_profile_edit_ts__month AS user__last_profile_edit_ts__month - , subq_1.user__last_profile_edit_ts__quarter AS user__last_profile_edit_ts__quarter - , subq_1.user__last_profile_edit_ts__year AS user__last_profile_edit_ts__year - , subq_1.user__last_profile_edit_ts__extract_year AS user__last_profile_edit_ts__extract_year - , subq_1.user__last_profile_edit_ts__extract_quarter AS user__last_profile_edit_ts__extract_quarter - , subq_1.user__last_profile_edit_ts__extract_month AS user__last_profile_edit_ts__extract_month - , subq_1.user__last_profile_edit_ts__extract_day AS user__last_profile_edit_ts__extract_day - , subq_1.user__last_profile_edit_ts__extract_dow AS user__last_profile_edit_ts__extract_dow - , subq_1.user__last_profile_edit_ts__extract_doy AS user__last_profile_edit_ts__extract_doy - , subq_1.user__bio_added_ts__second AS user__bio_added_ts__second - , subq_1.user__bio_added_ts__minute AS user__bio_added_ts__minute - , subq_1.user__bio_added_ts__hour AS user__bio_added_ts__hour - , subq_1.user__bio_added_ts__day AS user__bio_added_ts__day - , subq_1.user__bio_added_ts__week AS user__bio_added_ts__week - , subq_1.user__bio_added_ts__month AS user__bio_added_ts__month - , subq_1.user__bio_added_ts__quarter AS user__bio_added_ts__quarter - , subq_1.user__bio_added_ts__year AS user__bio_added_ts__year - , subq_1.user__bio_added_ts__extract_year AS user__bio_added_ts__extract_year - , subq_1.user__bio_added_ts__extract_quarter AS user__bio_added_ts__extract_quarter - , subq_1.user__bio_added_ts__extract_month AS user__bio_added_ts__extract_month - , subq_1.user__bio_added_ts__extract_day AS user__bio_added_ts__extract_day - , subq_1.user__bio_added_ts__extract_dow AS user__bio_added_ts__extract_dow - , subq_1.user__bio_added_ts__extract_doy AS user__bio_added_ts__extract_doy - , subq_1.user__last_login_ts__minute AS user__last_login_ts__minute - , subq_1.user__last_login_ts__hour AS user__last_login_ts__hour - , subq_1.user__last_login_ts__day AS user__last_login_ts__day - , subq_1.user__last_login_ts__week AS user__last_login_ts__week - , subq_1.user__last_login_ts__month AS user__last_login_ts__month - , subq_1.user__last_login_ts__quarter AS user__last_login_ts__quarter - , subq_1.user__last_login_ts__year AS user__last_login_ts__year - , subq_1.user__last_login_ts__extract_year AS user__last_login_ts__extract_year - , subq_1.user__last_login_ts__extract_quarter AS user__last_login_ts__extract_quarter - , subq_1.user__last_login_ts__extract_month AS user__last_login_ts__extract_month - , subq_1.user__last_login_ts__extract_day AS user__last_login_ts__extract_day - , subq_1.user__last_login_ts__extract_dow AS user__last_login_ts__extract_dow - , subq_1.user__last_login_ts__extract_doy AS user__last_login_ts__extract_doy - , subq_1.user__archived_at__hour AS user__archived_at__hour - , subq_1.user__archived_at__day AS user__archived_at__day - , subq_1.user__archived_at__week AS user__archived_at__week - , subq_1.user__archived_at__month AS user__archived_at__month - , subq_1.user__archived_at__quarter AS user__archived_at__quarter - , subq_1.user__archived_at__year AS user__archived_at__year - , subq_1.user__archived_at__extract_year AS user__archived_at__extract_year - , subq_1.user__archived_at__extract_quarter AS user__archived_at__extract_quarter - , subq_1.user__archived_at__extract_month AS user__archived_at__extract_month - , subq_1.user__archived_at__extract_day AS user__archived_at__extract_day - , subq_1.user__archived_at__extract_dow AS user__archived_at__extract_dow - , subq_1.user__archived_at__extract_doy AS user__archived_at__extract_doy - , 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 + subq_3.ts AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'archived_at' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.created_at__day + , subq_0.created_at__week + , subq_0.created_at__month + , subq_0.created_at__quarter + , subq_0.created_at__year + , subq_0.created_at__extract_year + , subq_0.created_at__extract_quarter + , subq_0.created_at__extract_month + , subq_0.created_at__extract_day + , subq_0.created_at__extract_dow + , subq_0.created_at__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.last_profile_edit_ts__millisecond + , subq_0.last_profile_edit_ts__second + , subq_0.last_profile_edit_ts__minute + , subq_0.last_profile_edit_ts__hour + , subq_0.last_profile_edit_ts__day + , subq_0.last_profile_edit_ts__week + , subq_0.last_profile_edit_ts__month + , subq_0.last_profile_edit_ts__quarter + , subq_0.last_profile_edit_ts__year + , subq_0.last_profile_edit_ts__extract_year + , subq_0.last_profile_edit_ts__extract_quarter + , subq_0.last_profile_edit_ts__extract_month + , subq_0.last_profile_edit_ts__extract_day + , subq_0.last_profile_edit_ts__extract_dow + , subq_0.last_profile_edit_ts__extract_doy + , subq_0.bio_added_ts__second + , subq_0.bio_added_ts__minute + , subq_0.bio_added_ts__hour + , subq_0.bio_added_ts__day + , subq_0.bio_added_ts__week + , subq_0.bio_added_ts__month + , subq_0.bio_added_ts__quarter + , subq_0.bio_added_ts__year + , subq_0.bio_added_ts__extract_year + , subq_0.bio_added_ts__extract_quarter + , subq_0.bio_added_ts__extract_month + , subq_0.bio_added_ts__extract_day + , subq_0.bio_added_ts__extract_dow + , subq_0.bio_added_ts__extract_doy + , subq_0.last_login_ts__minute + , subq_0.last_login_ts__hour + , subq_0.last_login_ts__day + , subq_0.last_login_ts__week + , subq_0.last_login_ts__month + , subq_0.last_login_ts__quarter + , subq_0.last_login_ts__year + , subq_0.last_login_ts__extract_year + , subq_0.last_login_ts__extract_quarter + , subq_0.last_login_ts__extract_month + , subq_0.last_login_ts__extract_day + , subq_0.last_login_ts__extract_dow + , subq_0.last_login_ts__extract_doy + , subq_0.archived_at__hour + , subq_0.archived_at__day + , subq_0.archived_at__week + , subq_0.archived_at__month + , subq_0.archived_at__quarter + , subq_0.archived_at__year + , subq_0.archived_at__extract_year + , subq_0.archived_at__extract_quarter + , subq_0.archived_at__extract_month + , subq_0.archived_at__extract_day + , subq_0.archived_at__extract_dow + , subq_0.archived_at__extract_doy + , subq_0.user__ds__day + , subq_0.user__ds__week + , subq_0.user__ds__month + , subq_0.user__ds__quarter + , subq_0.user__ds__year + , subq_0.user__ds__extract_year + , subq_0.user__ds__extract_quarter + , subq_0.user__ds__extract_month + , subq_0.user__ds__extract_day + , subq_0.user__ds__extract_dow + , subq_0.user__ds__extract_doy + , subq_0.user__created_at__day + , subq_0.user__created_at__week + , subq_0.user__created_at__month + , subq_0.user__created_at__quarter + , subq_0.user__created_at__year + , subq_0.user__created_at__extract_year + , subq_0.user__created_at__extract_quarter + , subq_0.user__created_at__extract_month + , subq_0.user__created_at__extract_day + , subq_0.user__created_at__extract_dow + , subq_0.user__created_at__extract_doy + , subq_0.user__ds_partitioned__day + , subq_0.user__ds_partitioned__week + , subq_0.user__ds_partitioned__month + , subq_0.user__ds_partitioned__quarter + , subq_0.user__ds_partitioned__year + , subq_0.user__ds_partitioned__extract_year + , subq_0.user__ds_partitioned__extract_quarter + , subq_0.user__ds_partitioned__extract_month + , subq_0.user__ds_partitioned__extract_day + , subq_0.user__ds_partitioned__extract_dow + , subq_0.user__ds_partitioned__extract_doy + , subq_0.user__last_profile_edit_ts__millisecond + , subq_0.user__last_profile_edit_ts__second + , subq_0.user__last_profile_edit_ts__minute + , subq_0.user__last_profile_edit_ts__hour + , subq_0.user__last_profile_edit_ts__day + , subq_0.user__last_profile_edit_ts__week + , subq_0.user__last_profile_edit_ts__month + , subq_0.user__last_profile_edit_ts__quarter + , subq_0.user__last_profile_edit_ts__year + , subq_0.user__last_profile_edit_ts__extract_year + , subq_0.user__last_profile_edit_ts__extract_quarter + , subq_0.user__last_profile_edit_ts__extract_month + , subq_0.user__last_profile_edit_ts__extract_day + , subq_0.user__last_profile_edit_ts__extract_dow + , subq_0.user__last_profile_edit_ts__extract_doy + , subq_0.user__bio_added_ts__second + , subq_0.user__bio_added_ts__minute + , subq_0.user__bio_added_ts__hour + , subq_0.user__bio_added_ts__day + , subq_0.user__bio_added_ts__week + , subq_0.user__bio_added_ts__month + , subq_0.user__bio_added_ts__quarter + , subq_0.user__bio_added_ts__year + , subq_0.user__bio_added_ts__extract_year + , subq_0.user__bio_added_ts__extract_quarter + , subq_0.user__bio_added_ts__extract_month + , subq_0.user__bio_added_ts__extract_day + , subq_0.user__bio_added_ts__extract_dow + , subq_0.user__bio_added_ts__extract_doy + , subq_0.user__last_login_ts__minute + , subq_0.user__last_login_ts__hour + , subq_0.user__last_login_ts__day + , subq_0.user__last_login_ts__week + , subq_0.user__last_login_ts__month + , subq_0.user__last_login_ts__quarter + , subq_0.user__last_login_ts__year + , subq_0.user__last_login_ts__extract_year + , subq_0.user__last_login_ts__extract_quarter + , subq_0.user__last_login_ts__extract_month + , subq_0.user__last_login_ts__extract_day + , subq_0.user__last_login_ts__extract_dow + , subq_0.user__last_login_ts__extract_doy + , subq_0.user__archived_at__hour + , subq_0.user__archived_at__day + , subq_0.user__archived_at__week + , subq_0.user__archived_at__month + , subq_0.user__archived_at__quarter + , subq_0.user__archived_at__year + , subq_0.user__archived_at__extract_year + , subq_0.user__archived_at__extract_quarter + , subq_0.user__archived_at__extract_month + , subq_0.user__archived_at__extract_day + , subq_0.user__archived_at__extract_dow + , subq_0.user__archived_at__extract_doy + , subq_0.archived_at__hour AS metric_time__hour + , subq_0.archived_at__day AS metric_time__day + , subq_0.archived_at__week AS metric_time__week + , subq_0.archived_at__month AS metric_time__month + , subq_0.archived_at__quarter AS metric_time__quarter + , subq_0.archived_at__year AS metric_time__year + , subq_0.archived_at__extract_year AS metric_time__extract_year + , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter + , subq_0.archived_at__extract_month AS metric_time__extract_month + , subq_0.archived_at__extract_day AS metric_time__extract_day + , subq_0.archived_at__extract_dow AS metric_time__extract_dow + , subq_0.archived_at__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.home_state + , subq_0.user__home_state + , subq_0.archived_users FROM ( - -- Time Spine - SELECT - subq_3.ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'archived_at' + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second - , subq_0.bio_added_ts__minute - , subq_0.bio_added_ts__hour - , subq_0.bio_added_ts__day - , subq_0.bio_added_ts__week - , subq_0.bio_added_ts__month - , subq_0.bio_added_ts__quarter - , subq_0.bio_added_ts__year - , subq_0.bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy - , subq_0.last_login_ts__minute - , subq_0.last_login_ts__hour - , subq_0.last_login_ts__day - , subq_0.last_login_ts__week - , subq_0.last_login_ts__month - , subq_0.last_login_ts__quarter - , subq_0.last_login_ts__year - , subq_0.last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month - , subq_0.last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy - , subq_0.archived_at__hour - , subq_0.archived_at__day - , subq_0.archived_at__week - , subq_0.archived_at__month - , subq_0.archived_at__quarter - , subq_0.archived_at__year - , subq_0.archived_at__extract_year - , subq_0.archived_at__extract_quarter - , subq_0.archived_at__extract_month - , subq_0.archived_at__extract_day - , subq_0.archived_at__extract_dow - , subq_0.archived_at__extract_doy - , subq_0.user__ds__day - , subq_0.user__ds__week - , subq_0.user__ds__month - , subq_0.user__ds__quarter - , subq_0.user__ds__year - , subq_0.user__ds__extract_year - , subq_0.user__ds__extract_quarter - , subq_0.user__ds__extract_month - , subq_0.user__ds__extract_day - , subq_0.user__ds__extract_dow - , subq_0.user__ds__extract_doy - , subq_0.user__created_at__day - , subq_0.user__created_at__week - , subq_0.user__created_at__month - , subq_0.user__created_at__quarter - , subq_0.user__created_at__year - , subq_0.user__created_at__extract_year - , subq_0.user__created_at__extract_quarter - , subq_0.user__created_at__extract_month - , subq_0.user__created_at__extract_day - , subq_0.user__created_at__extract_dow - , subq_0.user__created_at__extract_doy - , subq_0.user__ds_partitioned__day - , subq_0.user__ds_partitioned__week - , subq_0.user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day - , subq_0.user__bio_added_ts__week - , subq_0.user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute - , subq_0.user__last_login_ts__hour - , subq_0.user__last_login_ts__day - , subq_0.user__last_login_ts__week - , subq_0.user__last_login_ts__month - , subq_0.user__last_login_ts__quarter - , subq_0.user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour - , subq_0.user__archived_at__day - , subq_0.user__archived_at__week - , subq_0.user__archived_at__month - , subq_0.user__archived_at__quarter - , subq_0.user__archived_at__year - , subq_0.user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month - , subq_0.user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy - , subq_0.archived_at__hour AS metric_time__hour - , subq_0.archived_at__day AS metric_time__day - , subq_0.archived_at__week AS metric_time__week - , subq_0.archived_at__month AS metric_time__month - , subq_0.archived_at__quarter AS metric_time__quarter - , subq_0.archived_at__year AS metric_time__year - , subq_0.archived_at__extract_year AS metric_time__extract_year - , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter - , subq_0.archived_at__extract_month AS metric_time__extract_month - , subq_0.archived_at__extract_day AS metric_time__extract_day - , subq_0.archived_at__extract_dow AS metric_time__extract_dow - , subq_0.archived_at__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.home_state - , subq_0.user__home_state - , subq_0.archived_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - ) subq_1 - ON - subq_2.metric_time__hour - INTERVAL 1 hour = subq_1.metric_time__hour - ) subq_4 - ) subq_5 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_0 + ) subq_1 + ON + subq_2.metric_time__hour - INTERVAL 1 hour = subq_1.metric_time__hour + ) subq_4 GROUP BY - subq_5.metric_time__hour - ) subq_6 -) subq_7 + subq_4.metric_time__hour + ) subq_5 +) subq_6 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 66fbdfb392..357a94ff47 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 @@ -8,9 +8,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 + subq_10.ts AS metric_time__hour + , SUM(subq_8.archived_users) AS archived_users + FROM ***************************.mf_time_spine_hour subq_10 INNER JOIN ( -- Read Elements From Semantic Model 'users_ds_source' -- Metric Time Dimension 'archived_at' @@ -18,9 +18,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_8 ON - subq_11.ts - INTERVAL 1 hour = subq_9.metric_time__hour + subq_10.ts - INTERVAL 1 hour = subq_8.metric_time__hour GROUP BY - subq_11.ts -) subq_15 + subq_10.ts +) subq_13 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 f1543cd157..f6a1537256 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 @@ -1,613 +1,420 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__hour - , subq_8.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 ( -- 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_6.metric_time__hour + , subq_6.archived_users FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__hour AS metric_time__hour - , subq_4.archived_users AS archived_users + subq_4.metric_time__hour AS metric_time__hour + , subq_3.archived_users AS archived_users FROM ( -- Time Spine 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_5.ts AS metric_time__hour + FROM ***************************.mf_time_spine_hour subq_5 + WHERE subq_5.ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' + ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__hour - , SUM(subq_3.archived_users) AS archived_users + subq_2.metric_time__hour + , SUM(subq_2.archived_users) AS archived_users FROM ( + -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] -- Pass Only Elements: ['archived_users', 'metric_time__hour'] SELECT - subq_2.metric_time__hour - , subq_2.archived_users + subq_1.metric_time__hour + , subq_1.archived_users FROM ( - -- Constrain Time Range to [2020-01-01T02:00:00, 2020-01-01T05:00:00] + -- Metric Time Dimension 'archived_at' SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.created_at__day - , subq_1.created_at__week - , subq_1.created_at__month - , subq_1.created_at__quarter - , subq_1.created_at__year - , subq_1.created_at__extract_year - , subq_1.created_at__extract_quarter - , subq_1.created_at__extract_month - , subq_1.created_at__extract_day - , subq_1.created_at__extract_dow - , subq_1.created_at__extract_doy - , subq_1.ds_partitioned__day - , subq_1.ds_partitioned__week - , subq_1.ds_partitioned__month - , subq_1.ds_partitioned__quarter - , subq_1.ds_partitioned__year - , subq_1.ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy - , subq_1.last_profile_edit_ts__millisecond - , subq_1.last_profile_edit_ts__second - , subq_1.last_profile_edit_ts__minute - , subq_1.last_profile_edit_ts__hour - , subq_1.last_profile_edit_ts__day - , subq_1.last_profile_edit_ts__week - , subq_1.last_profile_edit_ts__month - , subq_1.last_profile_edit_ts__quarter - , subq_1.last_profile_edit_ts__year - , subq_1.last_profile_edit_ts__extract_year - , subq_1.last_profile_edit_ts__extract_quarter - , subq_1.last_profile_edit_ts__extract_month - , subq_1.last_profile_edit_ts__extract_day - , subq_1.last_profile_edit_ts__extract_dow - , subq_1.last_profile_edit_ts__extract_doy - , subq_1.bio_added_ts__second - , subq_1.bio_added_ts__minute - , subq_1.bio_added_ts__hour - , subq_1.bio_added_ts__day - , subq_1.bio_added_ts__week - , subq_1.bio_added_ts__month - , subq_1.bio_added_ts__quarter - , subq_1.bio_added_ts__year - , subq_1.bio_added_ts__extract_year - , subq_1.bio_added_ts__extract_quarter - , subq_1.bio_added_ts__extract_month - , subq_1.bio_added_ts__extract_day - , subq_1.bio_added_ts__extract_dow - , subq_1.bio_added_ts__extract_doy - , subq_1.last_login_ts__minute - , subq_1.last_login_ts__hour - , subq_1.last_login_ts__day - , subq_1.last_login_ts__week - , subq_1.last_login_ts__month - , subq_1.last_login_ts__quarter - , subq_1.last_login_ts__year - , subq_1.last_login_ts__extract_year - , subq_1.last_login_ts__extract_quarter - , subq_1.last_login_ts__extract_month - , subq_1.last_login_ts__extract_day - , subq_1.last_login_ts__extract_dow - , subq_1.last_login_ts__extract_doy - , subq_1.archived_at__hour - , subq_1.archived_at__day - , subq_1.archived_at__week - , subq_1.archived_at__month - , subq_1.archived_at__quarter - , subq_1.archived_at__year - , subq_1.archived_at__extract_year - , subq_1.archived_at__extract_quarter - , subq_1.archived_at__extract_month - , subq_1.archived_at__extract_day - , subq_1.archived_at__extract_dow - , subq_1.archived_at__extract_doy - , subq_1.user__ds__day - , subq_1.user__ds__week - , subq_1.user__ds__month - , subq_1.user__ds__quarter - , subq_1.user__ds__year - , subq_1.user__ds__extract_year - , subq_1.user__ds__extract_quarter - , subq_1.user__ds__extract_month - , subq_1.user__ds__extract_day - , subq_1.user__ds__extract_dow - , subq_1.user__ds__extract_doy - , subq_1.user__created_at__day - , subq_1.user__created_at__week - , subq_1.user__created_at__month - , subq_1.user__created_at__quarter - , subq_1.user__created_at__year - , subq_1.user__created_at__extract_year - , subq_1.user__created_at__extract_quarter - , subq_1.user__created_at__extract_month - , subq_1.user__created_at__extract_day - , subq_1.user__created_at__extract_dow - , subq_1.user__created_at__extract_doy - , subq_1.user__ds_partitioned__day - , subq_1.user__ds_partitioned__week - , subq_1.user__ds_partitioned__month - , subq_1.user__ds_partitioned__quarter - , subq_1.user__ds_partitioned__year - , subq_1.user__ds_partitioned__extract_year - , subq_1.user__ds_partitioned__extract_quarter - , subq_1.user__ds_partitioned__extract_month - , subq_1.user__ds_partitioned__extract_day - , subq_1.user__ds_partitioned__extract_dow - , subq_1.user__ds_partitioned__extract_doy - , subq_1.user__last_profile_edit_ts__millisecond - , subq_1.user__last_profile_edit_ts__second - , subq_1.user__last_profile_edit_ts__minute - , subq_1.user__last_profile_edit_ts__hour - , subq_1.user__last_profile_edit_ts__day - , subq_1.user__last_profile_edit_ts__week - , subq_1.user__last_profile_edit_ts__month - , subq_1.user__last_profile_edit_ts__quarter - , subq_1.user__last_profile_edit_ts__year - , subq_1.user__last_profile_edit_ts__extract_year - , subq_1.user__last_profile_edit_ts__extract_quarter - , subq_1.user__last_profile_edit_ts__extract_month - , subq_1.user__last_profile_edit_ts__extract_day - , subq_1.user__last_profile_edit_ts__extract_dow - , subq_1.user__last_profile_edit_ts__extract_doy - , subq_1.user__bio_added_ts__second - , subq_1.user__bio_added_ts__minute - , subq_1.user__bio_added_ts__hour - , subq_1.user__bio_added_ts__day - , subq_1.user__bio_added_ts__week - , subq_1.user__bio_added_ts__month - , subq_1.user__bio_added_ts__quarter - , subq_1.user__bio_added_ts__year - , subq_1.user__bio_added_ts__extract_year - , subq_1.user__bio_added_ts__extract_quarter - , subq_1.user__bio_added_ts__extract_month - , subq_1.user__bio_added_ts__extract_day - , subq_1.user__bio_added_ts__extract_dow - , subq_1.user__bio_added_ts__extract_doy - , subq_1.user__last_login_ts__minute - , subq_1.user__last_login_ts__hour - , subq_1.user__last_login_ts__day - , subq_1.user__last_login_ts__week - , subq_1.user__last_login_ts__month - , subq_1.user__last_login_ts__quarter - , subq_1.user__last_login_ts__year - , subq_1.user__last_login_ts__extract_year - , subq_1.user__last_login_ts__extract_quarter - , subq_1.user__last_login_ts__extract_month - , subq_1.user__last_login_ts__extract_day - , subq_1.user__last_login_ts__extract_dow - , subq_1.user__last_login_ts__extract_doy - , subq_1.user__archived_at__hour - , subq_1.user__archived_at__day - , subq_1.user__archived_at__week - , subq_1.user__archived_at__month - , subq_1.user__archived_at__quarter - , subq_1.user__archived_at__year - , subq_1.user__archived_at__extract_year - , subq_1.user__archived_at__extract_quarter - , subq_1.user__archived_at__extract_month - , subq_1.user__archived_at__extract_day - , subq_1.user__archived_at__extract_dow - , subq_1.user__archived_at__extract_doy - , subq_1.metric_time__hour - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.user - , subq_1.home_state - , subq_1.user__home_state - , subq_1.archived_users + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.created_at__day + , subq_0.created_at__week + , subq_0.created_at__month + , subq_0.created_at__quarter + , subq_0.created_at__year + , subq_0.created_at__extract_year + , subq_0.created_at__extract_quarter + , subq_0.created_at__extract_month + , subq_0.created_at__extract_day + , subq_0.created_at__extract_dow + , subq_0.created_at__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.last_profile_edit_ts__millisecond + , subq_0.last_profile_edit_ts__second + , subq_0.last_profile_edit_ts__minute + , subq_0.last_profile_edit_ts__hour + , subq_0.last_profile_edit_ts__day + , subq_0.last_profile_edit_ts__week + , subq_0.last_profile_edit_ts__month + , subq_0.last_profile_edit_ts__quarter + , subq_0.last_profile_edit_ts__year + , subq_0.last_profile_edit_ts__extract_year + , subq_0.last_profile_edit_ts__extract_quarter + , subq_0.last_profile_edit_ts__extract_month + , subq_0.last_profile_edit_ts__extract_day + , subq_0.last_profile_edit_ts__extract_dow + , subq_0.last_profile_edit_ts__extract_doy + , subq_0.bio_added_ts__second + , subq_0.bio_added_ts__minute + , subq_0.bio_added_ts__hour + , subq_0.bio_added_ts__day + , subq_0.bio_added_ts__week + , subq_0.bio_added_ts__month + , subq_0.bio_added_ts__quarter + , subq_0.bio_added_ts__year + , subq_0.bio_added_ts__extract_year + , subq_0.bio_added_ts__extract_quarter + , subq_0.bio_added_ts__extract_month + , subq_0.bio_added_ts__extract_day + , subq_0.bio_added_ts__extract_dow + , subq_0.bio_added_ts__extract_doy + , subq_0.last_login_ts__minute + , subq_0.last_login_ts__hour + , subq_0.last_login_ts__day + , subq_0.last_login_ts__week + , subq_0.last_login_ts__month + , subq_0.last_login_ts__quarter + , subq_0.last_login_ts__year + , subq_0.last_login_ts__extract_year + , subq_0.last_login_ts__extract_quarter + , subq_0.last_login_ts__extract_month + , subq_0.last_login_ts__extract_day + , subq_0.last_login_ts__extract_dow + , subq_0.last_login_ts__extract_doy + , subq_0.archived_at__hour + , subq_0.archived_at__day + , subq_0.archived_at__week + , subq_0.archived_at__month + , subq_0.archived_at__quarter + , subq_0.archived_at__year + , subq_0.archived_at__extract_year + , subq_0.archived_at__extract_quarter + , subq_0.archived_at__extract_month + , subq_0.archived_at__extract_day + , subq_0.archived_at__extract_dow + , subq_0.archived_at__extract_doy + , subq_0.user__ds__day + , subq_0.user__ds__week + , subq_0.user__ds__month + , subq_0.user__ds__quarter + , subq_0.user__ds__year + , subq_0.user__ds__extract_year + , subq_0.user__ds__extract_quarter + , subq_0.user__ds__extract_month + , subq_0.user__ds__extract_day + , subq_0.user__ds__extract_dow + , subq_0.user__ds__extract_doy + , subq_0.user__created_at__day + , subq_0.user__created_at__week + , subq_0.user__created_at__month + , subq_0.user__created_at__quarter + , subq_0.user__created_at__year + , subq_0.user__created_at__extract_year + , subq_0.user__created_at__extract_quarter + , subq_0.user__created_at__extract_month + , subq_0.user__created_at__extract_day + , subq_0.user__created_at__extract_dow + , subq_0.user__created_at__extract_doy + , subq_0.user__ds_partitioned__day + , subq_0.user__ds_partitioned__week + , subq_0.user__ds_partitioned__month + , subq_0.user__ds_partitioned__quarter + , subq_0.user__ds_partitioned__year + , subq_0.user__ds_partitioned__extract_year + , subq_0.user__ds_partitioned__extract_quarter + , subq_0.user__ds_partitioned__extract_month + , subq_0.user__ds_partitioned__extract_day + , subq_0.user__ds_partitioned__extract_dow + , subq_0.user__ds_partitioned__extract_doy + , subq_0.user__last_profile_edit_ts__millisecond + , subq_0.user__last_profile_edit_ts__second + , subq_0.user__last_profile_edit_ts__minute + , subq_0.user__last_profile_edit_ts__hour + , subq_0.user__last_profile_edit_ts__day + , subq_0.user__last_profile_edit_ts__week + , subq_0.user__last_profile_edit_ts__month + , subq_0.user__last_profile_edit_ts__quarter + , subq_0.user__last_profile_edit_ts__year + , subq_0.user__last_profile_edit_ts__extract_year + , subq_0.user__last_profile_edit_ts__extract_quarter + , subq_0.user__last_profile_edit_ts__extract_month + , subq_0.user__last_profile_edit_ts__extract_day + , subq_0.user__last_profile_edit_ts__extract_dow + , subq_0.user__last_profile_edit_ts__extract_doy + , subq_0.user__bio_added_ts__second + , subq_0.user__bio_added_ts__minute + , subq_0.user__bio_added_ts__hour + , subq_0.user__bio_added_ts__day + , subq_0.user__bio_added_ts__week + , subq_0.user__bio_added_ts__month + , subq_0.user__bio_added_ts__quarter + , subq_0.user__bio_added_ts__year + , subq_0.user__bio_added_ts__extract_year + , subq_0.user__bio_added_ts__extract_quarter + , subq_0.user__bio_added_ts__extract_month + , subq_0.user__bio_added_ts__extract_day + , subq_0.user__bio_added_ts__extract_dow + , subq_0.user__bio_added_ts__extract_doy + , subq_0.user__last_login_ts__minute + , subq_0.user__last_login_ts__hour + , subq_0.user__last_login_ts__day + , subq_0.user__last_login_ts__week + , subq_0.user__last_login_ts__month + , subq_0.user__last_login_ts__quarter + , subq_0.user__last_login_ts__year + , subq_0.user__last_login_ts__extract_year + , subq_0.user__last_login_ts__extract_quarter + , subq_0.user__last_login_ts__extract_month + , subq_0.user__last_login_ts__extract_day + , subq_0.user__last_login_ts__extract_dow + , subq_0.user__last_login_ts__extract_doy + , subq_0.user__archived_at__hour + , subq_0.user__archived_at__day + , subq_0.user__archived_at__week + , subq_0.user__archived_at__month + , subq_0.user__archived_at__quarter + , subq_0.user__archived_at__year + , subq_0.user__archived_at__extract_year + , subq_0.user__archived_at__extract_quarter + , subq_0.user__archived_at__extract_month + , subq_0.user__archived_at__extract_day + , subq_0.user__archived_at__extract_dow + , subq_0.user__archived_at__extract_doy + , subq_0.archived_at__hour AS metric_time__hour + , subq_0.archived_at__day AS metric_time__day + , subq_0.archived_at__week AS metric_time__week + , subq_0.archived_at__month AS metric_time__month + , subq_0.archived_at__quarter AS metric_time__quarter + , subq_0.archived_at__year AS metric_time__year + , subq_0.archived_at__extract_year AS metric_time__extract_year + , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter + , subq_0.archived_at__extract_month AS metric_time__extract_month + , subq_0.archived_at__extract_day AS metric_time__extract_day + , subq_0.archived_at__extract_dow AS metric_time__extract_dow + , subq_0.archived_at__extract_doy AS metric_time__extract_doy + , subq_0.user + , subq_0.home_state + , subq_0.user__home_state + , subq_0.archived_users FROM ( - -- Metric Time Dimension 'archived_at' + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.last_profile_edit_ts__millisecond - , subq_0.last_profile_edit_ts__second - , subq_0.last_profile_edit_ts__minute - , subq_0.last_profile_edit_ts__hour - , subq_0.last_profile_edit_ts__day - , subq_0.last_profile_edit_ts__week - , subq_0.last_profile_edit_ts__month - , subq_0.last_profile_edit_ts__quarter - , subq_0.last_profile_edit_ts__year - , subq_0.last_profile_edit_ts__extract_year - , subq_0.last_profile_edit_ts__extract_quarter - , subq_0.last_profile_edit_ts__extract_month - , subq_0.last_profile_edit_ts__extract_day - , subq_0.last_profile_edit_ts__extract_dow - , subq_0.last_profile_edit_ts__extract_doy - , subq_0.bio_added_ts__second - , subq_0.bio_added_ts__minute - , subq_0.bio_added_ts__hour - , subq_0.bio_added_ts__day - , subq_0.bio_added_ts__week - , subq_0.bio_added_ts__month - , subq_0.bio_added_ts__quarter - , subq_0.bio_added_ts__year - , subq_0.bio_added_ts__extract_year - , subq_0.bio_added_ts__extract_quarter - , subq_0.bio_added_ts__extract_month - , subq_0.bio_added_ts__extract_day - , subq_0.bio_added_ts__extract_dow - , subq_0.bio_added_ts__extract_doy - , subq_0.last_login_ts__minute - , subq_0.last_login_ts__hour - , subq_0.last_login_ts__day - , subq_0.last_login_ts__week - , subq_0.last_login_ts__month - , subq_0.last_login_ts__quarter - , subq_0.last_login_ts__year - , subq_0.last_login_ts__extract_year - , subq_0.last_login_ts__extract_quarter - , subq_0.last_login_ts__extract_month - , subq_0.last_login_ts__extract_day - , subq_0.last_login_ts__extract_dow - , subq_0.last_login_ts__extract_doy - , subq_0.archived_at__hour - , subq_0.archived_at__day - , subq_0.archived_at__week - , subq_0.archived_at__month - , subq_0.archived_at__quarter - , subq_0.archived_at__year - , subq_0.archived_at__extract_year - , subq_0.archived_at__extract_quarter - , subq_0.archived_at__extract_month - , subq_0.archived_at__extract_day - , subq_0.archived_at__extract_dow - , subq_0.archived_at__extract_doy - , subq_0.user__ds__day - , subq_0.user__ds__week - , subq_0.user__ds__month - , subq_0.user__ds__quarter - , subq_0.user__ds__year - , subq_0.user__ds__extract_year - , subq_0.user__ds__extract_quarter - , subq_0.user__ds__extract_month - , subq_0.user__ds__extract_day - , subq_0.user__ds__extract_dow - , subq_0.user__ds__extract_doy - , subq_0.user__created_at__day - , subq_0.user__created_at__week - , subq_0.user__created_at__month - , subq_0.user__created_at__quarter - , subq_0.user__created_at__year - , subq_0.user__created_at__extract_year - , subq_0.user__created_at__extract_quarter - , subq_0.user__created_at__extract_month - , subq_0.user__created_at__extract_day - , subq_0.user__created_at__extract_dow - , subq_0.user__created_at__extract_doy - , subq_0.user__ds_partitioned__day - , subq_0.user__ds_partitioned__week - , subq_0.user__ds_partitioned__month - , subq_0.user__ds_partitioned__quarter - , subq_0.user__ds_partitioned__year - , subq_0.user__ds_partitioned__extract_year - , subq_0.user__ds_partitioned__extract_quarter - , subq_0.user__ds_partitioned__extract_month - , subq_0.user__ds_partitioned__extract_day - , subq_0.user__ds_partitioned__extract_dow - , subq_0.user__ds_partitioned__extract_doy - , subq_0.user__last_profile_edit_ts__millisecond - , subq_0.user__last_profile_edit_ts__second - , subq_0.user__last_profile_edit_ts__minute - , subq_0.user__last_profile_edit_ts__hour - , subq_0.user__last_profile_edit_ts__day - , subq_0.user__last_profile_edit_ts__week - , subq_0.user__last_profile_edit_ts__month - , subq_0.user__last_profile_edit_ts__quarter - , subq_0.user__last_profile_edit_ts__year - , subq_0.user__last_profile_edit_ts__extract_year - , subq_0.user__last_profile_edit_ts__extract_quarter - , subq_0.user__last_profile_edit_ts__extract_month - , subq_0.user__last_profile_edit_ts__extract_day - , subq_0.user__last_profile_edit_ts__extract_dow - , subq_0.user__last_profile_edit_ts__extract_doy - , subq_0.user__bio_added_ts__second - , subq_0.user__bio_added_ts__minute - , subq_0.user__bio_added_ts__hour - , subq_0.user__bio_added_ts__day - , subq_0.user__bio_added_ts__week - , subq_0.user__bio_added_ts__month - , subq_0.user__bio_added_ts__quarter - , subq_0.user__bio_added_ts__year - , subq_0.user__bio_added_ts__extract_year - , subq_0.user__bio_added_ts__extract_quarter - , subq_0.user__bio_added_ts__extract_month - , subq_0.user__bio_added_ts__extract_day - , subq_0.user__bio_added_ts__extract_dow - , subq_0.user__bio_added_ts__extract_doy - , subq_0.user__last_login_ts__minute - , subq_0.user__last_login_ts__hour - , subq_0.user__last_login_ts__day - , subq_0.user__last_login_ts__week - , subq_0.user__last_login_ts__month - , subq_0.user__last_login_ts__quarter - , subq_0.user__last_login_ts__year - , subq_0.user__last_login_ts__extract_year - , subq_0.user__last_login_ts__extract_quarter - , subq_0.user__last_login_ts__extract_month - , subq_0.user__last_login_ts__extract_day - , subq_0.user__last_login_ts__extract_dow - , subq_0.user__last_login_ts__extract_doy - , subq_0.user__archived_at__hour - , subq_0.user__archived_at__day - , subq_0.user__archived_at__week - , subq_0.user__archived_at__month - , subq_0.user__archived_at__quarter - , subq_0.user__archived_at__year - , subq_0.user__archived_at__extract_year - , subq_0.user__archived_at__extract_quarter - , subq_0.user__archived_at__extract_month - , subq_0.user__archived_at__extract_day - , subq_0.user__archived_at__extract_dow - , subq_0.user__archived_at__extract_doy - , subq_0.archived_at__hour AS metric_time__hour - , subq_0.archived_at__day AS metric_time__day - , subq_0.archived_at__week AS metric_time__week - , subq_0.archived_at__month AS metric_time__month - , subq_0.archived_at__quarter AS metric_time__quarter - , subq_0.archived_at__year AS metric_time__year - , subq_0.archived_at__extract_year AS metric_time__extract_year - , subq_0.archived_at__extract_quarter AS metric_time__extract_quarter - , subq_0.archived_at__extract_month AS metric_time__extract_month - , subq_0.archived_at__extract_day AS metric_time__extract_day - , subq_0.archived_at__extract_dow AS metric_time__extract_dow - , subq_0.archived_at__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.home_state - , subq_0.user__home_state - , subq_0.archived_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_0 - ) subq_1 - WHERE subq_1.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' - ) subq_2 - ) subq_3 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_0 + ) subq_1 + WHERE subq_1.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' + ) subq_2 GROUP BY - subq_3.metric_time__hour - ) subq_4 + subq_2.metric_time__hour + ) subq_3 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_4.metric_time__hour = subq_3.metric_time__hour + ) subq_6 + WHERE subq_6.metric_time__hour BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' +) subq_7 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 7fef407456..814810629c 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 @@ -2,15 +2,15 @@ -- 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_12.metric_time__hour AS metric_time__hour + , subq_11.archived_users AS subdaily_join_to_time_spine_metric FROM ( -- Time Spine SELECT ts AS metric_time__hour - FROM ***************************.mf_time_spine_hour subq_15 + FROM ***************************.mf_time_spine_hour subq_13 WHERE ts BETWEEN '2020-01-01 02:00:00' AND '2020-01-01 05:00:00' -) subq_14 +) subq_12 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -26,10 +26,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_10 GROUP BY metric_time__hour -) subq_13 +) subq_11 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_12.metric_time__hour = subq_11.metric_time__hour +WHERE subq_12.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_subdaily_time_constraint_without_metrics__plan0.sql b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_without_metrics__plan0.sql index 43dbe48625..d7a2795822 100644 --- a/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_without_metrics__plan0.sql +++ b/tests_metricflow/snapshots/test_granularity_date_part_rendering.py/SqlQueryPlan/DuckDB/test_subdaily_time_constraint_without_metrics__plan0.sql @@ -1,89 +1,58 @@ +-- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] -- Pass Only Elements: ['metric_time__second',] SELECT - subq_2.metric_time__second + subq_1.metric_time__second FROM ( - -- Constrain Time Range to [2020-01-01T00:00:02, 2020-01-01T00:00:08] + -- Metric Time Dimension 'ts' SELECT - subq_1.ts__second - , subq_1.ts__minute - , subq_1.ts__hour - , subq_1.ts__day - , subq_1.ts__week - , subq_1.ts__month - , subq_1.ts__quarter - , subq_1.ts__year - , subq_1.ts__extract_year - , subq_1.ts__extract_quarter - , subq_1.ts__extract_month - , subq_1.ts__extract_day - , subq_1.ts__extract_dow - , subq_1.ts__extract_doy - , subq_1.metric_time__second - , subq_1.metric_time__minute - , subq_1.metric_time__hour - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy + subq_0.ts__second + , subq_0.ts__minute + , subq_0.ts__hour + , subq_0.ts__day + , subq_0.ts__week + , subq_0.ts__month + , subq_0.ts__quarter + , subq_0.ts__year + , subq_0.ts__extract_year + , subq_0.ts__extract_quarter + , subq_0.ts__extract_month + , subq_0.ts__extract_day + , subq_0.ts__extract_dow + , subq_0.ts__extract_doy + , subq_0.ts__second AS metric_time__second + , subq_0.ts__minute AS metric_time__minute + , subq_0.ts__hour AS metric_time__hour + , subq_0.ts__day AS metric_time__day + , subq_0.ts__week AS metric_time__week + , subq_0.ts__month AS metric_time__month + , subq_0.ts__quarter AS metric_time__quarter + , subq_0.ts__year AS metric_time__year + , subq_0.ts__extract_year AS metric_time__extract_year + , subq_0.ts__extract_quarter AS metric_time__extract_quarter + , subq_0.ts__extract_month AS metric_time__extract_month + , subq_0.ts__extract_day AS metric_time__extract_day + , subq_0.ts__extract_dow AS metric_time__extract_dow + , subq_0.ts__extract_doy AS metric_time__extract_doy FROM ( - -- Metric Time Dimension 'ts' + -- Time Spine SELECT - subq_0.ts__second - , subq_0.ts__minute - , subq_0.ts__hour - , subq_0.ts__day - , subq_0.ts__week - , subq_0.ts__month - , subq_0.ts__quarter - , subq_0.ts__year - , subq_0.ts__extract_year - , subq_0.ts__extract_quarter - , subq_0.ts__extract_month - , subq_0.ts__extract_day - , subq_0.ts__extract_dow - , subq_0.ts__extract_doy - , subq_0.ts__second AS metric_time__second - , subq_0.ts__minute AS metric_time__minute - , subq_0.ts__hour AS metric_time__hour - , subq_0.ts__day AS metric_time__day - , subq_0.ts__week AS metric_time__week - , subq_0.ts__month AS metric_time__month - , subq_0.ts__quarter AS metric_time__quarter - , subq_0.ts__year AS metric_time__year - , subq_0.ts__extract_year AS metric_time__extract_year - , subq_0.ts__extract_quarter AS metric_time__extract_quarter - , subq_0.ts__extract_month AS metric_time__extract_month - , subq_0.ts__extract_day AS metric_time__extract_day - , subq_0.ts__extract_dow AS metric_time__extract_dow - , subq_0.ts__extract_doy AS metric_time__extract_doy - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second - , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute - , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour - , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day - , DATE_TRUNC('week', time_spine_src_28003.ts) AS ts__week - , DATE_TRUNC('month', time_spine_src_28003.ts) AS ts__month - , DATE_TRUNC('quarter', time_spine_src_28003.ts) AS ts__quarter - , DATE_TRUNC('year', time_spine_src_28003.ts) AS ts__year - , EXTRACT(year FROM time_spine_src_28003.ts) AS ts__extract_year - , EXTRACT(quarter FROM time_spine_src_28003.ts) AS ts__extract_quarter - , EXTRACT(month FROM time_spine_src_28003.ts) AS ts__extract_month - , EXTRACT(day FROM time_spine_src_28003.ts) AS ts__extract_day - , EXTRACT(isodow FROM time_spine_src_28003.ts) AS ts__extract_dow - , EXTRACT(doy FROM time_spine_src_28003.ts) AS ts__extract_doy - FROM ***************************.mf_time_spine_second time_spine_src_28003 - ) subq_0 - ) subq_1 - WHERE subq_1.metric_time__second BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' -) subq_2 + DATE_TRUNC('second', time_spine_src_28003.ts) AS ts__second + , DATE_TRUNC('minute', time_spine_src_28003.ts) AS ts__minute + , DATE_TRUNC('hour', time_spine_src_28003.ts) AS ts__hour + , DATE_TRUNC('day', time_spine_src_28003.ts) AS ts__day + , DATE_TRUNC('week', time_spine_src_28003.ts) AS ts__week + , DATE_TRUNC('month', time_spine_src_28003.ts) AS ts__month + , DATE_TRUNC('quarter', time_spine_src_28003.ts) AS ts__quarter + , DATE_TRUNC('year', time_spine_src_28003.ts) AS ts__year + , EXTRACT(year FROM time_spine_src_28003.ts) AS ts__extract_year + , EXTRACT(quarter FROM time_spine_src_28003.ts) AS ts__extract_quarter + , EXTRACT(month FROM time_spine_src_28003.ts) AS ts__extract_month + , EXTRACT(day FROM time_spine_src_28003.ts) AS ts__extract_day + , EXTRACT(isodow FROM time_spine_src_28003.ts) AS ts__extract_dow + , EXTRACT(doy FROM time_spine_src_28003.ts) AS ts__extract_doy + FROM ***************************.mf_time_spine_second time_spine_src_28003 + ) subq_0 +) subq_1 +WHERE subq_1.metric_time__second BETWEEN '2020-01-01 00:00:02' AND '2020-01-01 00:00:08' GROUP BY - subq_2.metric_time__second + subq_1.metric_time__second diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0.sql index 799e437abe..5856387817 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0.sql @@ -1,253 +1,140 @@ +-- Constrain Output with WHERE -- Pass Only Elements: ['listing',] SELECT - subq_8.listing + subq_5.listing FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs SELECT - subq_7.listing - , subq_7.lux_listing - , subq_7.listing__lux_listing - , subq_7.listing__bookings + subq_0.listing AS listing + , subq_0.lux_listing AS lux_listing + , subq_0.listing__lux_listing AS listing__lux_listing + , subq_4.listing__bookings AS listing__bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'lux_listing_mapping' SELECT - subq_0.listing AS listing - , subq_0.lux_listing AS lux_listing - , subq_0.listing__lux_listing AS listing__lux_listing - , subq_6.listing__bookings AS listing__bookings + lux_listing_mapping_src_28000.listing_id AS listing + , lux_listing_mapping_src_28000.lux_listing_id AS lux_listing + , lux_listing_mapping_src_28000.lux_listing_id AS listing__lux_listing + FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_28000 + ) subq_0 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing', 'listing__bookings'] + SELECT + subq_3.listing + , subq_3.bookings AS listing__bookings FROM ( - -- Read Elements From Semantic Model 'lux_listing_mapping' - SELECT - lux_listing_mapping_src_28000.listing_id AS listing - , lux_listing_mapping_src_28000.lux_listing_id AS lux_listing - , lux_listing_mapping_src_28000.lux_listing_id AS listing__lux_listing - FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_28000 - ) subq_0 - FULL OUTER JOIN ( - -- Pass Only Elements: ['listing', 'listing__bookings'] + -- Aggregate Measures SELECT - subq_5.listing - , subq_5.listing__bookings + subq_2.listing + , SUM(subq_2.bookings) AS bookings FROM ( - -- Compute Metrics via Expressions + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'listing'] SELECT - subq_4.listing - , subq_4.bookings AS listing__bookings + subq_1.listing + , subq_1.bookings FROM ( - -- Aggregate Measures + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_3.listing - , SUM(subq_3.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'listing'] - SELECT - subq_2.listing - , subq_2.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.ds_partitioned__day - , subq_1.ds_partitioned__week - , subq_1.ds_partitioned__month - , subq_1.ds_partitioned__quarter - , subq_1.ds_partitioned__year - , subq_1.ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy - , subq_1.paid_at__day - , subq_1.paid_at__week - , subq_1.paid_at__month - , subq_1.paid_at__quarter - , subq_1.paid_at__year - , subq_1.paid_at__extract_year - , subq_1.paid_at__extract_quarter - , subq_1.paid_at__extract_month - , subq_1.paid_at__extract_day - , subq_1.paid_at__extract_dow - , subq_1.paid_at__extract_doy - , subq_1.booking__ds__day - , subq_1.booking__ds__week - , subq_1.booking__ds__month - , subq_1.booking__ds__quarter - , subq_1.booking__ds__year - , subq_1.booking__ds__extract_year - , subq_1.booking__ds__extract_quarter - , subq_1.booking__ds__extract_month - , subq_1.booking__ds__extract_day - , subq_1.booking__ds__extract_dow - , subq_1.booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day - , subq_1.booking__paid_at__week - , subq_1.booking__paid_at__month - , subq_1.booking__paid_at__quarter - , subq_1.booking__paid_at__year - , subq_1.booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy - , subq_1.ds__day AS metric_time__day - , subq_1.ds__week AS metric_time__week - , subq_1.ds__month AS metric_time__month - , subq_1.ds__quarter AS metric_time__quarter - , subq_1.ds__year AS metric_time__year - , subq_1.ds__extract_year AS metric_time__extract_year - , subq_1.ds__extract_quarter AS metric_time__extract_quarter - , subq_1.ds__extract_month AS metric_time__extract_month - , subq_1.ds__extract_day AS metric_time__extract_day - , subq_1.ds__extract_dow AS metric_time__extract_dow - , subq_1.ds__extract_doy AS metric_time__extract_doy - , subq_1.listing - , subq_1.guest - , subq_1.host - , subq_1.booking__listing - , subq_1.booking__guest - , subq_1.booking__host - , subq_1.is_instant - , subq_1.booking__is_instant - , subq_1.bookings - , subq_1.instant_bookings - , subq_1.booking_value - , subq_1.max_booking_value - , subq_1.min_booking_value - , subq_1.bookers - , subq_1.average_booking_value - , subq_1.referred_bookings - , subq_1.median_booking_value - , subq_1.booking_value_p99 - , subq_1.discrete_booking_value_p99 - , subq_1.approximate_continuous_booking_value_p99 - , subq_1.approximate_discrete_booking_value_p99 - 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_1 - ) subq_2 - ) subq_3 - GROUP BY - subq_3.listing - ) subq_4 - ) subq_5 - ) subq_6 - ON - subq_0.listing = subq_6.listing - ) subq_7 - WHERE listing__bookings > 2 -) subq_8 + 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_1 + ) subq_2 + GROUP BY + subq_2.listing + ) subq_3 + ) subq_4 + ON + subq_0.listing = subq_4.listing +) subq_5 +WHERE listing__bookings > 2 GROUP BY - subq_8.listing + subq_5.listing diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0_optimized.sql index d79ef0aa09..8ca3e0a079 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values_query_with_metric_filter__plan0_optimized.sql @@ -6,7 +6,7 @@ FROM ( -- Join Standard Outputs SELECT lux_listing_mapping_src_28000.listing_id AS listing - , subq_15.listing__bookings AS listing__bookings + , subq_10.listing__bookings AS listing__bookings FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_28000 FULL OUTER JOIN ( -- Aggregate Measures @@ -23,13 +23,13 @@ FROM ( listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_12 + ) subq_8 GROUP BY listing - ) subq_15 + ) subq_10 ON - lux_listing_mapping_src_28000.listing_id = subq_15.listing -) subq_16 + lux_listing_mapping_src_28000.listing_id = subq_10.listing +) subq_11 WHERE listing__bookings > 2 GROUP BY listing diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0.sql index e5dc490b67..9a983d3b5a 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0.sql @@ -1,457 +1,239 @@ -- Compute Metrics via Expressions SELECT - subq_13.bookers + subq_8.bookers FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_12.bookers) AS bookers + COUNT(DISTINCT subq_7.bookers) AS bookers FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookers',] SELECT - subq_11.bookers + subq_6.bookers FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookers', 'guest__booking_value'] SELECT - subq_10.guest__booking_value - , subq_10.bookers + subq_5.guest__booking_value AS guest__booking_value + , subq_1.bookers AS bookers FROM ( - -- Pass Only Elements: ['bookers', 'guest__booking_value'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'guest'] SELECT - subq_9.guest__booking_value - , subq_9.bookers + subq_0.guest + , subq_0.bookers FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.guest AS guest - , subq_8.guest__booking_value AS guest__booking_value - , subq_2.bookers AS bookers + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['guest', 'guest__booking_value'] + SELECT + subq_4.guest + , subq_4.booking_value AS guest__booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_3.guest + , SUM(subq_3.booking_value) AS booking_value FROM ( - -- Pass Only Elements: ['bookers', 'guest'] - SELECT - subq_1.guest - , subq_1.bookers - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['guest', 'guest__booking_value'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['booking_value', 'guest'] SELECT - subq_7.guest - , subq_7.guest__booking_value + subq_2.guest + , subq_2.booking_value FROM ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_6.guest - , subq_6.booking_value AS guest__booking_value - FROM ( - -- Aggregate Measures - SELECT - subq_5.guest - , SUM(subq_5.booking_value) AS booking_value - FROM ( - -- Pass Only Elements: ['booking_value', 'guest'] - SELECT - subq_4.guest - , subq_4.booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.paid_at__day - , subq_3.paid_at__week - , subq_3.paid_at__month - , subq_3.paid_at__quarter - , subq_3.paid_at__year - , subq_3.paid_at__extract_year - , subq_3.paid_at__extract_quarter - , subq_3.paid_at__extract_month - , subq_3.paid_at__extract_day - , subq_3.paid_at__extract_dow - , subq_3.paid_at__extract_doy - , subq_3.booking__ds__day - , subq_3.booking__ds__week - , subq_3.booking__ds__month - , subq_3.booking__ds__quarter - , subq_3.booking__ds__year - , subq_3.booking__ds__extract_year - , subq_3.booking__ds__extract_quarter - , subq_3.booking__ds__extract_month - , subq_3.booking__ds__extract_day - , subq_3.booking__ds__extract_dow - , subq_3.booking__ds__extract_doy - , subq_3.booking__ds_partitioned__day - , subq_3.booking__ds_partitioned__week - , subq_3.booking__ds_partitioned__month - , subq_3.booking__ds_partitioned__quarter - , subq_3.booking__ds_partitioned__year - , subq_3.booking__ds_partitioned__extract_year - , subq_3.booking__ds_partitioned__extract_quarter - , subq_3.booking__ds_partitioned__extract_month - , subq_3.booking__ds_partitioned__extract_day - , subq_3.booking__ds_partitioned__extract_dow - , subq_3.booking__ds_partitioned__extract_doy - , subq_3.booking__paid_at__day - , subq_3.booking__paid_at__week - , subq_3.booking__paid_at__month - , subq_3.booking__paid_at__quarter - , subq_3.booking__paid_at__year - , subq_3.booking__paid_at__extract_year - , subq_3.booking__paid_at__extract_quarter - , subq_3.booking__paid_at__extract_month - , subq_3.booking__paid_at__extract_day - , subq_3.booking__paid_at__extract_dow - , subq_3.booking__paid_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.guest - , subq_3.host - , subq_3.booking__listing - , subq_3.booking__guest - , subq_3.booking__host - , subq_3.is_instant - , subq_3.booking__is_instant - , subq_3.bookings - , subq_3.instant_bookings - , subq_3.booking_value - , subq_3.max_booking_value - , subq_3.min_booking_value - , subq_3.bookers - , subq_3.average_booking_value - , subq_3.referred_bookings - , subq_3.median_booking_value - , subq_3.booking_value_p99 - , subq_3.discrete_booking_value_p99 - , subq_3.approximate_continuous_booking_value_p99 - , subq_3.approximate_discrete_booking_value_p99 - 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_3 - ) subq_4 - ) subq_5 - GROUP BY - subq_5.guest - ) subq_6 - ) subq_7 - ) subq_8 - ON - subq_2.guest = subq_8.guest - ) subq_9 - ) subq_10 - WHERE guest__booking_value > 1.00 - ) subq_11 - ) subq_12 -) subq_13 + 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_2 + ) subq_3 + GROUP BY + subq_3.guest + ) subq_4 + ) subq_5 + ON + subq_1.guest = subq_5.guest + ) subq_6 + WHERE guest__booking_value > 1.00 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0_optimized.sql index 93d184feee..8a63ce5afa 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_by_metric_in_same_semantic_model_as_queried_metric__plan0_optimized.sql @@ -8,8 +8,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookers', 'guest__booking_value'] SELECT - subq_22.guest__booking_value AS guest__booking_value - , subq_16.bookers AS bookers + subq_14.guest__booking_value AS guest__booking_value + , subq_10.bookers AS bookers FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -18,7 +18,7 @@ FROM ( guest_id AS guest , guest_id AS bookers FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_10 LEFT OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -32,8 +32,8 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY guest_id - ) subq_22 + ) subq_14 ON - subq_16.guest = subq_22.guest -) subq_24 + subq_10.guest = subq_14.guest +) subq_15 WHERE guest__booking_value > 1.00 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_conversion_metric__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_conversion_metric__plan0.sql index 56c2dfee56..b5a3076732 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_conversion_metric__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_conversion_metric__plan0.sql @@ -1,555 +1,370 @@ -- Compute Metrics via Expressions SELECT - subq_24.listings + subq_17.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_23.listings) AS listings + SUM(subq_16.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings',] SELECT - subq_22.listings + subq_15.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__visit_buy_conversion_rate'] SELECT - subq_21.user__visit_buy_conversion_rate - , subq_21.listings + subq_14.user__visit_buy_conversion_rate AS user__visit_buy_conversion_rate + , subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'user__visit_buy_conversion_rate'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'user'] SELECT - subq_20.user__visit_buy_conversion_rate - , subq_20.listings + subq_0.user + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.user AS user - , subq_19.user__visit_buy_conversion_rate AS user__visit_buy_conversion_rate - , subq_2.listings AS listings + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['user', 'user__visit_buy_conversion_rate'] + SELECT + subq_13.user + , CAST(subq_13.buys AS DOUBLE) / CAST(NULLIF(subq_13.visits, 0) AS DOUBLE) AS user__visit_buy_conversion_rate + FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_4.user, subq_12.user) AS user + , MAX(subq_4.visits) AS visits + , MAX(subq_12.buys) AS buys FROM ( - -- Pass Only Elements: ['listings', 'user'] + -- Aggregate Measures SELECT - subq_1.user - , subq_1.listings + subq_3.user + , SUM(subq_3.visits) AS visits FROM ( -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'user'] SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_2.user + , subq_2.visits FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Read Elements From Semantic Model 'visits_source' SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['user', 'user__visit_buy_conversion_rate'] + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_2 + ) subq_3 + GROUP BY + subq_3.user + ) subq_4 + FULL OUTER JOIN ( + -- Aggregate Measures SELECT - subq_18.user - , subq_18.user__visit_buy_conversion_rate + subq_11.user + , SUM(subq_11.buys) AS buys FROM ( - -- Compute Metrics via Expressions + -- Find conversions for user within the range of INF + -- Pass Only Elements: ['buys', 'user'] SELECT - subq_17.user - , CAST(subq_17.buys AS DOUBLE) / CAST(NULLIF(subq_17.visits, 0) AS DOUBLE) AS user__visit_buy_conversion_rate + subq_10.user + , subq_10.buys FROM ( - -- Combine Aggregated Outputs - SELECT - COALESCE(subq_6.user, subq_16.user) AS user - , MAX(subq_6.visits) AS visits - , MAX(subq_16.buys) AS buys + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_6.visits) OVER ( + PARTITION BY + subq_9.user + , subq_9.ds__day + , subq_9.mf_internal_uuid + ORDER BY subq_6.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_6.ds__day) OVER ( + PARTITION BY + subq_9.user + , subq_9.ds__day + , subq_9.mf_internal_uuid + ORDER BY subq_6.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_6.user) OVER ( + PARTITION BY + subq_9.user + , subq_9.ds__day + , subq_9.mf_internal_uuid + ORDER BY subq_6.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_9.mf_internal_uuid AS mf_internal_uuid + , subq_9.buys AS buys FROM ( - -- Aggregate Measures + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'ds__day', 'user'] SELECT - subq_5.user - , SUM(subq_5.visits) AS visits + subq_5.ds__day + , subq_5.user + , subq_5.visits FROM ( - -- Pass Only Elements: ['visits', 'user'] + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_4.user - , subq_4.visits - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.visit__ds__day - , subq_3.visit__ds__week - , subq_3.visit__ds__month - , subq_3.visit__ds__quarter - , subq_3.visit__ds__year - , subq_3.visit__ds__extract_year - , subq_3.visit__ds__extract_quarter - , subq_3.visit__ds__extract_month - , subq_3.visit__ds__extract_day - , subq_3.visit__ds__extract_dow - , subq_3.visit__ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.user - , subq_3.session - , subq_3.visit__user - , subq_3.visit__session - , subq_3.referrer_id - , subq_3.visit__referrer_id - , subq_3.visits - , subq_3.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_3 - ) subq_4 + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 ) subq_5 - GROUP BY - subq_5.user ) subq_6 - FULL OUTER JOIN ( - -- Aggregate Measures + INNER JOIN ( + -- Add column with generated UUID SELECT - subq_15.user - , SUM(subq_15.buys) AS buys + subq_8.ds__day + , subq_8.ds__week + , subq_8.ds__month + , subq_8.ds__quarter + , subq_8.ds__year + , subq_8.ds__extract_year + , subq_8.ds__extract_quarter + , subq_8.ds__extract_month + , subq_8.ds__extract_day + , subq_8.ds__extract_dow + , subq_8.ds__extract_doy + , subq_8.buy__ds__day + , subq_8.buy__ds__week + , subq_8.buy__ds__month + , subq_8.buy__ds__quarter + , subq_8.buy__ds__year + , subq_8.buy__ds__extract_year + , subq_8.buy__ds__extract_quarter + , subq_8.buy__ds__extract_month + , subq_8.buy__ds__extract_day + , subq_8.buy__ds__extract_dow + , subq_8.buy__ds__extract_doy + , subq_8.metric_time__day + , subq_8.metric_time__week + , subq_8.metric_time__month + , subq_8.metric_time__quarter + , subq_8.metric_time__year + , subq_8.metric_time__extract_year + , subq_8.metric_time__extract_quarter + , subq_8.metric_time__extract_month + , subq_8.metric_time__extract_day + , subq_8.metric_time__extract_dow + , subq_8.metric_time__extract_doy + , subq_8.user + , subq_8.session_id + , subq_8.buy__user + , subq_8.buy__session_id + , subq_8.buys + , subq_8.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ( - -- Pass Only Elements: ['buys', 'user'] + -- Metric Time Dimension 'ds' SELECT - subq_14.user - , subq_14.buys + 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.buy__ds__day + , subq_7.buy__ds__week + , subq_7.buy__ds__month + , subq_7.buy__ds__quarter + , subq_7.buy__ds__year + , subq_7.buy__ds__extract_year + , subq_7.buy__ds__extract_quarter + , subq_7.buy__ds__extract_month + , subq_7.buy__ds__extract_day + , subq_7.buy__ds__extract_dow + , subq_7.buy__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_id + , subq_7.buy__user + , subq_7.buy__session_id + , subq_7.buys + , subq_7.buyers FROM ( - -- Find conversions for user within the range of INF + -- Read Elements From Semantic Model 'buys_source' SELECT - subq_13.ds__day - , subq_13.user - , subq_13.buys - , subq_13.visits - FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_9.visits) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_9.ds__day) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_9.user) OVER ( - PARTITION BY - subq_12.user - , subq_12.ds__day - , subq_12.mf_internal_uuid - ORDER BY subq_9.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_12.mf_internal_uuid AS mf_internal_uuid - , subq_12.buys AS buys - FROM ( - -- Pass Only Elements: ['visits', 'ds__day', 'user'] - SELECT - subq_8.ds__day - , subq_8.user - , subq_8.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 - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_7 - ) subq_8 - ) subq_9 - INNER JOIN ( - -- Add column with generated UUID - SELECT - subq_11.ds__day - , subq_11.ds__week - , subq_11.ds__month - , subq_11.ds__quarter - , subq_11.ds__year - , subq_11.ds__extract_year - , subq_11.ds__extract_quarter - , subq_11.ds__extract_month - , subq_11.ds__extract_day - , subq_11.ds__extract_dow - , subq_11.ds__extract_doy - , subq_11.buy__ds__day - , subq_11.buy__ds__week - , subq_11.buy__ds__month - , subq_11.buy__ds__quarter - , subq_11.buy__ds__year - , subq_11.buy__ds__extract_year - , subq_11.buy__ds__extract_quarter - , subq_11.buy__ds__extract_month - , subq_11.buy__ds__extract_day - , subq_11.buy__ds__extract_dow - , subq_11.buy__ds__extract_doy - , subq_11.metric_time__day - , subq_11.metric_time__week - , subq_11.metric_time__month - , subq_11.metric_time__quarter - , subq_11.metric_time__year - , subq_11.metric_time__extract_year - , subq_11.metric_time__extract_quarter - , subq_11.metric_time__extract_month - , subq_11.metric_time__extract_day - , subq_11.metric_time__extract_dow - , subq_11.metric_time__extract_doy - , subq_11.user - , subq_11.session_id - , subq_11.buy__user - , subq_11.buy__session_id - , subq_11.buys - , subq_11.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.buy__ds__day - , subq_10.buy__ds__week - , subq_10.buy__ds__month - , subq_10.buy__ds__quarter - , subq_10.buy__ds__year - , subq_10.buy__ds__extract_year - , subq_10.buy__ds__extract_quarter - , subq_10.buy__ds__extract_month - , subq_10.buy__ds__extract_day - , subq_10.buy__ds__extract_dow - , subq_10.buy__ds__extract_doy - , subq_10.ds__day AS metric_time__day - , subq_10.ds__week AS metric_time__week - , subq_10.ds__month AS metric_time__month - , subq_10.ds__quarter AS metric_time__quarter - , subq_10.ds__year AS metric_time__year - , subq_10.ds__extract_year AS metric_time__extract_year - , subq_10.ds__extract_quarter AS metric_time__extract_quarter - , subq_10.ds__extract_month AS metric_time__extract_month - , subq_10.ds__extract_day AS metric_time__extract_day - , subq_10.ds__extract_dow AS metric_time__extract_dow - , subq_10.ds__extract_doy AS metric_time__extract_doy - , subq_10.user - , subq_10.session_id - , subq_10.buy__user - , subq_10.buy__session_id - , subq_10.buys - , subq_10.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_10 - ) subq_11 - ) subq_12 - ON - ( - subq_9.user = subq_12.user - ) AND ( - (subq_9.ds__day <= subq_12.ds__day) - ) - ) subq_13 - ) subq_14 - ) subq_15 - GROUP BY - subq_15.user - ) subq_16 + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_7 + ) subq_8 + ) subq_9 ON - subq_6.user = subq_16.user - GROUP BY - COALESCE(subq_6.user, subq_16.user) - ) subq_17 - ) subq_18 - ) subq_19 + (subq_6.user = subq_9.user) AND ((subq_6.ds__day <= subq_9.ds__day)) + ) subq_10 + ) subq_11 + GROUP BY + subq_11.user + ) subq_12 ON - subq_2.user = subq_19.user - ) subq_20 - ) subq_21 - WHERE user__visit_buy_conversion_rate > 2 - ) subq_22 - ) subq_23 -) subq_24 + subq_4.user = subq_12.user + GROUP BY + COALESCE(subq_4.user, subq_12.user) + ) subq_13 + ) subq_14 + ON + subq_1.user = subq_14.user + ) subq_15 + WHERE user__visit_buy_conversion_rate > 2 + ) subq_16 +) subq_17 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_conversion_metric__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_conversion_metric__plan0_optimized.sql index 306cbe445e..7cdbf4500e 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_conversion_metric__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_conversion_metric__plan0_optimized.sql @@ -8,8 +8,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['listings', 'user__visit_buy_conversion_rate'] SELECT - CAST(subq_42.buys AS DOUBLE) / CAST(NULLIF(subq_42.visits, 0) AS DOUBLE) AS user__visit_buy_conversion_rate - , subq_27.listings AS listings + CAST(subq_31.buys AS DOUBLE) / CAST(NULLIF(subq_31.visits, 0) AS DOUBLE) AS user__visit_buy_conversion_rate + , subq_19.listings AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -18,17 +18,17 @@ FROM ( user_id AS user , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_27 + ) subq_19 LEFT OUTER JOIN ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_31.user, subq_41.user) AS user - , MAX(subq_31.visits) AS visits - , MAX(subq_41.buys) AS buys + COALESCE(subq_22.user, subq_30.user) AS user + , MAX(subq_22.visits) AS visits + , MAX(subq_30.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_30.user + subq_21.user , SUM(visits) AS visits FROM ( -- Read Elements From Semantic Model 'visits_source' @@ -38,46 +38,46 @@ FROM ( user_id AS user , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_30 + ) subq_21 GROUP BY - subq_30.user - ) subq_31 + subq_21.user + ) subq_22 FULL OUTER JOIN ( -- Find conversions for user within the range of INF -- Pass Only Elements: ['buys', 'user'] -- Aggregate Measures SELECT - subq_38.user + subq_28.user , SUM(buys) AS buys FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_34.visits) OVER ( + FIRST_VALUE(subq_24.visits) OVER ( PARTITION BY - subq_37.user - , subq_37.ds__day - , subq_37.mf_internal_uuid - ORDER BY subq_34.ds__day DESC + subq_27.user + , subq_27.ds__day + , subq_27.mf_internal_uuid + ORDER BY subq_24.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_34.ds__day) OVER ( + , FIRST_VALUE(subq_24.ds__day) OVER ( PARTITION BY - subq_37.user - , subq_37.ds__day - , subq_37.mf_internal_uuid - ORDER BY subq_34.ds__day DESC + subq_27.user + , subq_27.ds__day + , subq_27.mf_internal_uuid + ORDER BY subq_24.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_34.user) OVER ( + , FIRST_VALUE(subq_24.user) OVER ( PARTITION BY - subq_37.user - , subq_37.ds__day - , subq_37.mf_internal_uuid - ORDER BY subq_34.ds__day DESC + subq_27.user + , subq_27.ds__day + , subq_27.mf_internal_uuid + ORDER BY subq_24.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_37.mf_internal_uuid AS mf_internal_uuid - , subq_37.buys AS buys + , subq_27.mf_internal_uuid AS mf_internal_uuid + , subq_27.buys AS buys FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -87,7 +87,7 @@ FROM ( , user_id AS user , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_34 + ) subq_24 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -98,23 +98,23 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_37 + ) subq_27 ON ( - subq_34.user = subq_37.user + subq_24.user = subq_27.user ) AND ( - (subq_34.ds__day <= subq_37.ds__day) + (subq_24.ds__day <= subq_27.ds__day) ) - ) subq_38 + ) subq_28 GROUP BY - subq_38.user - ) subq_41 + subq_28.user + ) subq_30 ON - subq_31.user = subq_41.user + subq_22.user = subq_30.user GROUP BY - COALESCE(subq_31.user, subq_41.user) - ) subq_42 + COALESCE(subq_22.user, subq_30.user) + ) subq_31 ON - subq_27.user = subq_42.user -) subq_46 + subq_19.user = subq_31.user +) subq_33 WHERE user__visit_buy_conversion_rate > 2 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_group_by_has_local_entity_prefix__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_group_by_has_local_entity_prefix__plan0.sql index 1b6946e2c8..3d8487e5c1 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_group_by_has_local_entity_prefix__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_group_by_has_local_entity_prefix__plan0.sql @@ -1,106 +1,210 @@ -- Compute Metrics via Expressions SELECT - subq_18.listings + subq_11.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_17.listings) AS listings + SUM(subq_10.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings',] SELECT - subq_16.listings + subq_9.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__listing__user__average_booking_value'] SELECT - subq_15.user__listing__user__average_booking_value - , subq_15.listings + subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'user__listing__user__average_booking_value'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'user'] SELECT - subq_14.user__listing__user__average_booking_value - , subq_14.listings + subq_0.user + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.user AS user - , subq_13.listing__user AS user__listing__user - , subq_13.listing__user__average_booking_value AS user__listing__user__average_booking_value - , subq_2.listings AS listings + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing__user', 'listing__user__average_booking_value'] + SELECT + subq_7.listing__user + , subq_7.average_booking_value AS listing__user__average_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_6.listing__user + , AVG(subq_6.average_booking_value) AS average_booking_value FROM ( - -- Pass Only Elements: ['listings', 'user'] + -- Join Standard Outputs + -- Pass Only Elements: ['average_booking_value', 'listing__user'] SELECT - subq_1.user - , subq_1.listings + subq_3.average_booking_value AS average_booking_value FROM ( -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['average_booking_value', 'listing'] + SELECT + subq_2.listing + , subq_2.average_booking_value + 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_2 + ) subq_3 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listing', 'user'] SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_4.listing + , subq_4.user FROM ( -- Read Elements From Semantic Model 'listings_latest' SELECT @@ -161,388 +265,18 @@ 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing__user', 'listing__user__average_booking_value'] - SELECT - subq_12.listing__user - , subq_12.listing__user__average_booking_value - FROM ( - -- Compute Metrics via Expressions - SELECT - subq_11.listing__user - , subq_11.average_booking_value AS listing__user__average_booking_value - FROM ( - -- Aggregate Measures - SELECT - subq_10.listing__user - , AVG(subq_10.average_booking_value) AS average_booking_value - FROM ( - -- Pass Only Elements: ['average_booking_value', 'listing__user'] - SELECT - subq_9.listing__user - , subq_9.average_booking_value - FROM ( - -- Join Standard Outputs - SELECT - subq_5.listing AS listing - , subq_8.user AS listing__user - , subq_5.average_booking_value AS average_booking_value - FROM ( - -- Pass Only Elements: ['average_booking_value', 'listing'] - SELECT - subq_4.listing - , subq_4.average_booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.paid_at__day - , subq_3.paid_at__week - , subq_3.paid_at__month - , subq_3.paid_at__quarter - , subq_3.paid_at__year - , subq_3.paid_at__extract_year - , subq_3.paid_at__extract_quarter - , subq_3.paid_at__extract_month - , subq_3.paid_at__extract_day - , subq_3.paid_at__extract_dow - , subq_3.paid_at__extract_doy - , subq_3.booking__ds__day - , subq_3.booking__ds__week - , subq_3.booking__ds__month - , subq_3.booking__ds__quarter - , subq_3.booking__ds__year - , subq_3.booking__ds__extract_year - , subq_3.booking__ds__extract_quarter - , subq_3.booking__ds__extract_month - , subq_3.booking__ds__extract_day - , subq_3.booking__ds__extract_dow - , subq_3.booking__ds__extract_doy - , subq_3.booking__ds_partitioned__day - , subq_3.booking__ds_partitioned__week - , subq_3.booking__ds_partitioned__month - , subq_3.booking__ds_partitioned__quarter - , subq_3.booking__ds_partitioned__year - , subq_3.booking__ds_partitioned__extract_year - , subq_3.booking__ds_partitioned__extract_quarter - , subq_3.booking__ds_partitioned__extract_month - , subq_3.booking__ds_partitioned__extract_day - , subq_3.booking__ds_partitioned__extract_dow - , subq_3.booking__ds_partitioned__extract_doy - , subq_3.booking__paid_at__day - , subq_3.booking__paid_at__week - , subq_3.booking__paid_at__month - , subq_3.booking__paid_at__quarter - , subq_3.booking__paid_at__year - , subq_3.booking__paid_at__extract_year - , subq_3.booking__paid_at__extract_quarter - , subq_3.booking__paid_at__extract_month - , subq_3.booking__paid_at__extract_day - , subq_3.booking__paid_at__extract_dow - , subq_3.booking__paid_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.guest - , subq_3.host - , subq_3.booking__listing - , subq_3.booking__guest - , subq_3.booking__host - , subq_3.is_instant - , subq_3.booking__is_instant - , subq_3.bookings - , subq_3.instant_bookings - , subq_3.booking_value - , subq_3.max_booking_value - , subq_3.min_booking_value - , subq_3.bookers - , subq_3.average_booking_value - , subq_3.referred_bookings - , subq_3.median_booking_value - , subq_3.booking_value_p99 - , subq_3.discrete_booking_value_p99 - , subq_3.approximate_continuous_booking_value_p99 - , subq_3.approximate_discrete_booking_value_p99 - 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_3 - ) subq_4 - ) subq_5 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'user'] - SELECT - subq_7.listing - , subq_7.user - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.created_at__day - , subq_6.created_at__week - , subq_6.created_at__month - , subq_6.created_at__quarter - , subq_6.created_at__year - , subq_6.created_at__extract_year - , subq_6.created_at__extract_quarter - , subq_6.created_at__extract_month - , subq_6.created_at__extract_day - , subq_6.created_at__extract_dow - , subq_6.created_at__extract_doy - , subq_6.listing__ds__day - , subq_6.listing__ds__week - , subq_6.listing__ds__month - , subq_6.listing__ds__quarter - , subq_6.listing__ds__year - , subq_6.listing__ds__extract_year - , subq_6.listing__ds__extract_quarter - , subq_6.listing__ds__extract_month - , subq_6.listing__ds__extract_day - , subq_6.listing__ds__extract_dow - , subq_6.listing__ds__extract_doy - , subq_6.listing__created_at__day - , subq_6.listing__created_at__week - , subq_6.listing__created_at__month - , subq_6.listing__created_at__quarter - , subq_6.listing__created_at__year - , subq_6.listing__created_at__extract_year - , subq_6.listing__created_at__extract_quarter - , subq_6.listing__created_at__extract_month - , subq_6.listing__created_at__extract_day - , subq_6.listing__created_at__extract_dow - , subq_6.listing__created_at__extract_doy - , subq_6.ds__day AS metric_time__day - , subq_6.ds__week AS metric_time__week - , subq_6.ds__month AS metric_time__month - , subq_6.ds__quarter AS metric_time__quarter - , subq_6.ds__year AS metric_time__year - , subq_6.ds__extract_year AS metric_time__extract_year - , subq_6.ds__extract_quarter AS metric_time__extract_quarter - , subq_6.ds__extract_month AS metric_time__extract_month - , subq_6.ds__extract_day AS metric_time__extract_day - , subq_6.ds__extract_dow AS metric_time__extract_dow - , subq_6.ds__extract_doy AS metric_time__extract_doy - , subq_6.listing - , subq_6.user - , subq_6.listing__user - , subq_6.country_latest - , subq_6.is_lux_latest - , subq_6.capacity_latest - , subq_6.listing__country_latest - , subq_6.listing__is_lux_latest - , subq_6.listing__capacity_latest - , subq_6.listings - , subq_6.largest_listing - , subq_6.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_6 - ) subq_7 - ) subq_8 - ON - subq_5.listing = subq_8.listing - ) subq_9 - ) subq_10 - GROUP BY - subq_10.listing__user - ) subq_11 - ) subq_12 - ) subq_13 - ON - subq_2.user = subq_13.listing__user - ) subq_14 - ) subq_15 - WHERE user__listing__user__average_booking_value > 1 - ) subq_16 - ) subq_17 -) subq_18 + ) subq_4 + ) subq_5 + ON + subq_3.listing = subq_5.listing + ) subq_6 + GROUP BY + subq_6.listing__user + ) subq_7 + ) subq_8 + ON + subq_1.user = subq_8.listing__user + ) subq_9 + WHERE user__listing__user__average_booking_value > 1 + ) subq_10 +) subq_11 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_group_by_has_local_entity_prefix__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_group_by_has_local_entity_prefix__plan0_optimized.sql index 8a2de81699..4ec49cd4dd 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_group_by_has_local_entity_prefix__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_group_by_has_local_entity_prefix__plan0_optimized.sql @@ -1,42 +1,12 @@ +-- Read Elements From Semantic Model 'listings_latest' +-- Metric Time Dimension 'ds' +-- Pass Only Elements: ['listings', 'user'] +-- Join Standard Outputs +-- Pass Only Elements: ['listings', 'user__listing__user__average_booking_value'] -- Constrain Output with WHERE -- Pass Only Elements: ['listings',] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - SUM(listings) AS listings -FROM ( - -- Join Standard Outputs - -- Pass Only Elements: ['listings', 'user__listing__user__average_booking_value'] - SELECT - subq_32.listing__user__average_booking_value AS user__listing__user__average_booking_value - , subq_21.listings AS listings - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - -- Metric Time Dimension 'ds' - -- Pass Only Elements: ['listings', 'user'] - SELECT - user_id AS user - , 1 AS listings - FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_21 - LEFT OUTER JOIN ( - -- Join Standard Outputs - -- Pass Only Elements: ['average_booking_value', 'listing__user'] - -- Aggregate Measures - -- Compute Metrics via Expressions - -- Pass Only Elements: ['listing__user', 'listing__user__average_booking_value'] - SELECT - listings_latest_src_28000.user_id AS listing__user - , AVG(bookings_source_src_28000.booking_value) AS listing__user__average_booking_value - FROM ***************************.fct_bookings bookings_source_src_28000 - LEFT OUTER JOIN - ***************************.dim_listings_latest listings_latest_src_28000 - ON - bookings_source_src_28000.listing_id = listings_latest_src_28000.listing_id - GROUP BY - listings_latest_src_28000.user_id - ) subq_32 - ON - subq_21.user = subq_32.listing__user -) subq_34 -WHERE user__listing__user__average_booking_value > 1 + SUM(1) AS listings +FROM ***************************.dim_listings_latest listings_latest_src_28000 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_multi_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_multi_hop__plan0.sql index 3146c0bc2f..fe7d84f45f 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_multi_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_multi_hop__plan0.sql @@ -1,694 +1,416 @@ -- Compute Metrics via Expressions SELECT - subq_22.third_hop_count + subq_14.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_21.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_13.third_hop_count) AS third_hop_count FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['third_hop_count',] SELECT - subq_20.third_hop_count + subq_12.third_hop_count FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count'] SELECT - subq_19.customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count - , subq_19.third_hop_count + subq_1.third_hop_count AS third_hop_count FROM ( - -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count'] + -- Metric Time Dimension 'third_hop_ds' + -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_18.customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count - , subq_18.third_hop_count + subq_0.customer_third_hop_id + , subq_0.third_hop_count FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'third_hop_table' SELECT - subq_2.customer_third_hop_id AS customer_third_hop_id - , subq_17.account_id__customer_id__customer_third_hop_id AS customer_third_hop_id__account_id__customer_id__customer_third_hop_id - , subq_17.account_id__customer_id__customer_third_hop_id__txn_count AS customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count - , subq_2.third_hop_count AS third_hop_count + third_hop_table_src_22000.customer_third_hop_id AS third_hop_count + , third_hop_table_src_22000.value + , DATE_TRUNC('day', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__day + , DATE_TRUNC('week', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__week + , DATE_TRUNC('month', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__month + , DATE_TRUNC('quarter', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__quarter + , DATE_TRUNC('year', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__year + , EXTRACT(year FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_year + , EXTRACT(quarter FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_quarter + , EXTRACT(month FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_month + , EXTRACT(day FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_day + , EXTRACT(isodow FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_dow + , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_doy + , third_hop_table_src_22000.value AS customer_third_hop_id__value + , DATE_TRUNC('day', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__day + , DATE_TRUNC('week', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__week + , DATE_TRUNC('month', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__month + , DATE_TRUNC('quarter', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__quarter + , DATE_TRUNC('year', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__year + , EXTRACT(year FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_year + , EXTRACT(quarter FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_quarter + , EXTRACT(month FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_month + , EXTRACT(day FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_day + , EXTRACT(isodow FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_dow + , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy + , third_hop_table_src_22000.customer_third_hop_id + FROM ***************************.third_hop_table third_hop_table_src_22000 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['account_id__customer_id__customer_third_hop_id', 'account_id__customer_id__customer_third_hop_id__txn_count'] + SELECT + subq_10.account_id__customer_id__customer_third_hop_id + , subq_10.txn_count AS account_id__customer_id__customer_third_hop_id__txn_count + FROM ( + -- Aggregate Measures + SELECT + subq_9.account_id__customer_id__customer_third_hop_id + , SUM(subq_9.txn_count) AS txn_count FROM ( - -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] + -- Join Standard Outputs + -- Pass Only Elements: ['txn_count', 'account_id__customer_id__customer_third_hop_id'] SELECT - subq_1.customer_third_hop_id - , subq_1.third_hop_count + subq_3.txn_count AS txn_count FROM ( - -- Metric Time Dimension 'third_hop_ds' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['txn_count', 'ds_partitioned__day', 'account_id'] SELECT - subq_0.third_hop_ds__day - , subq_0.third_hop_ds__week - , subq_0.third_hop_ds__month - , subq_0.third_hop_ds__quarter - , subq_0.third_hop_ds__year - , subq_0.third_hop_ds__extract_year - , subq_0.third_hop_ds__extract_quarter - , subq_0.third_hop_ds__extract_month - , subq_0.third_hop_ds__extract_day - , subq_0.third_hop_ds__extract_dow - , subq_0.third_hop_ds__extract_doy - , subq_0.customer_third_hop_id__third_hop_ds__day - , subq_0.customer_third_hop_id__third_hop_ds__week - , subq_0.customer_third_hop_id__third_hop_ds__month - , subq_0.customer_third_hop_id__third_hop_ds__quarter - , subq_0.customer_third_hop_id__third_hop_ds__year - , subq_0.customer_third_hop_id__third_hop_ds__extract_year - , subq_0.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_0.customer_third_hop_id__third_hop_ds__extract_month - , subq_0.customer_third_hop_id__third_hop_ds__extract_day - , subq_0.customer_third_hop_id__third_hop_ds__extract_dow - , subq_0.customer_third_hop_id__third_hop_ds__extract_doy - , subq_0.third_hop_ds__day AS metric_time__day - , subq_0.third_hop_ds__week AS metric_time__week - , subq_0.third_hop_ds__month AS metric_time__month - , subq_0.third_hop_ds__quarter AS metric_time__quarter - , subq_0.third_hop_ds__year AS metric_time__year - , subq_0.third_hop_ds__extract_year AS metric_time__extract_year - , subq_0.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_0.third_hop_ds__extract_month AS metric_time__extract_month - , subq_0.third_hop_ds__extract_day AS metric_time__extract_day - , subq_0.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_0.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_0.customer_third_hop_id - , subq_0.value - , subq_0.customer_third_hop_id__value - , subq_0.third_hop_count + subq_2.ds_partitioned__day + , subq_2.account_id + , subq_2.txn_count FROM ( - -- Read Elements From Semantic Model 'third_hop_table' + -- Read Elements From Semantic Model 'account_month_txns' SELECT - third_hop_table_src_22000.customer_third_hop_id AS third_hop_count - , third_hop_table_src_22000.value - , DATE_TRUNC('day', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__day - , DATE_TRUNC('week', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__week - , DATE_TRUNC('month', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__month - , DATE_TRUNC('quarter', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__quarter - , DATE_TRUNC('year', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__year - , EXTRACT(year FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_year - , EXTRACT(quarter FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_quarter - , EXTRACT(month FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_month - , EXTRACT(day FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_day - , EXTRACT(isodow FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_dow - , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_doy - , third_hop_table_src_22000.value AS customer_third_hop_id__value - , DATE_TRUNC('day', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__day - , DATE_TRUNC('week', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__week - , DATE_TRUNC('month', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__month - , DATE_TRUNC('quarter', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__quarter - , DATE_TRUNC('year', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__year - , EXTRACT(year FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_year - , EXTRACT(quarter FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_quarter - , EXTRACT(month FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_month - , EXTRACT(day FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_day - , EXTRACT(isodow FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_dow - , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy - , third_hop_table_src_22000.customer_third_hop_id - FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['account_id__customer_id__customer_third_hop_id', 'account_id__customer_id__customer_third_hop_id__txn_count'] - SELECT - subq_16.account_id__customer_id__customer_third_hop_id - , subq_16.account_id__customer_id__customer_third_hop_id__txn_count - FROM ( - -- Compute Metrics via Expressions + account_month_txns_src_22000.txn_count + , DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', account_month_txns_src_22000.ds) AS ds__day + , DATE_TRUNC('week', account_month_txns_src_22000.ds) AS ds__week + , DATE_TRUNC('month', account_month_txns_src_22000.ds) AS ds__month + , DATE_TRUNC('quarter', account_month_txns_src_22000.ds) AS ds__quarter + , DATE_TRUNC('year', account_month_txns_src_22000.ds) AS ds__year + , EXTRACT(year FROM account_month_txns_src_22000.ds) AS ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_22000.ds) AS ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_22000.ds) AS ds__extract_month + , EXTRACT(day FROM account_month_txns_src_22000.ds) AS ds__extract_day + , EXTRACT(isodow FROM account_month_txns_src_22000.ds) AS ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_22000.ds) AS ds__extract_doy + , account_month_txns_src_22000.account_month + , DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(day FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(isodow FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , DATE_TRUNC('day', account_month_txns_src_22000.ds) AS account_id__ds__day + , DATE_TRUNC('week', account_month_txns_src_22000.ds) AS account_id__ds__week + , DATE_TRUNC('month', account_month_txns_src_22000.ds) AS account_id__ds__month + , DATE_TRUNC('quarter', account_month_txns_src_22000.ds) AS account_id__ds__quarter + , DATE_TRUNC('year', account_month_txns_src_22000.ds) AS account_id__ds__year + , EXTRACT(year FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_month + , EXTRACT(day FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_day + , EXTRACT(isodow FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_doy + , account_month_txns_src_22000.account_month AS account_id__account_month + , account_month_txns_src_22000.account_id + FROM ***************************.account_month_txns account_month_txns_src_22000 + ) subq_2 + ) subq_3 + LEFT OUTER JOIN ( + -- Join Standard Outputs + -- Pass Only Elements: ['ds_partitioned__day', 'account_id', 'customer_id__customer_third_hop_id'] SELECT - subq_15.account_id__customer_id__customer_third_hop_id - , subq_15.txn_count AS account_id__customer_id__customer_third_hop_id__txn_count + subq_5.ds_partitioned__day AS ds_partitioned__day + , subq_5.account_id AS account_id FROM ( - -- Aggregate Measures + -- Metric Time Dimension 'ds_partitioned' + SELECT + 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.account_id__ds_partitioned__day + , subq_4.account_id__ds_partitioned__week + , subq_4.account_id__ds_partitioned__month + , subq_4.account_id__ds_partitioned__quarter + , subq_4.account_id__ds_partitioned__year + , subq_4.account_id__ds_partitioned__extract_year + , subq_4.account_id__ds_partitioned__extract_quarter + , subq_4.account_id__ds_partitioned__extract_month + , subq_4.account_id__ds_partitioned__extract_day + , subq_4.account_id__ds_partitioned__extract_dow + , subq_4.account_id__ds_partitioned__extract_doy + , subq_4.bridge_account__ds_partitioned__day + , subq_4.bridge_account__ds_partitioned__week + , subq_4.bridge_account__ds_partitioned__month + , subq_4.bridge_account__ds_partitioned__quarter + , subq_4.bridge_account__ds_partitioned__year + , subq_4.bridge_account__ds_partitioned__extract_year + , subq_4.bridge_account__ds_partitioned__extract_quarter + , subq_4.bridge_account__ds_partitioned__extract_month + , subq_4.bridge_account__ds_partitioned__extract_day + , subq_4.bridge_account__ds_partitioned__extract_dow + , subq_4.bridge_account__ds_partitioned__extract_doy + , subq_4.ds_partitioned__day AS metric_time__day + , subq_4.ds_partitioned__week AS metric_time__week + , subq_4.ds_partitioned__month AS metric_time__month + , subq_4.ds_partitioned__quarter AS metric_time__quarter + , subq_4.ds_partitioned__year AS metric_time__year + , subq_4.ds_partitioned__extract_year AS metric_time__extract_year + , subq_4.ds_partitioned__extract_quarter AS metric_time__extract_quarter + , subq_4.ds_partitioned__extract_month AS metric_time__extract_month + , subq_4.ds_partitioned__extract_day AS metric_time__extract_day + , subq_4.ds_partitioned__extract_dow AS metric_time__extract_dow + , subq_4.ds_partitioned__extract_doy AS metric_time__extract_doy + , subq_4.account_id + , subq_4.customer_id + , subq_4.account_id__customer_id + , subq_4.bridge_account__account_id + , subq_4.bridge_account__customer_id + , subq_4.extra_dim + , subq_4.account_id__extra_dim + , subq_4.bridge_account__extra_dim + , subq_4.account_customer_combos + FROM ( + -- Read Elements From Semantic Model 'bridge_table' + SELECT + account_id || customer_id AS account_customer_combos + , bridge_table_src_22000.extra_dim + , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_doy + , bridge_table_src_22000.extra_dim AS account_id__extra_dim + , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , bridge_table_src_22000.extra_dim AS bridge_account__extra_dim + , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_day + , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy + , bridge_table_src_22000.account_id + , bridge_table_src_22000.customer_id + , bridge_table_src_22000.customer_id AS account_id__customer_id + , bridge_table_src_22000.account_id AS bridge_account__account_id + , bridge_table_src_22000.customer_id AS bridge_account__customer_id + FROM ***************************.bridge_table bridge_table_src_22000 + ) subq_4 + ) subq_5 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'acquired_ds' + -- Pass Only Elements: [ + -- 'country', + -- 'customer_id__country', + -- 'customer_third_hop_id__country', + -- 'acquired_ds__day', + -- 'acquired_ds__week', + -- 'acquired_ds__month', + -- 'acquired_ds__quarter', + -- 'acquired_ds__year', + -- 'acquired_ds__extract_year', + -- 'acquired_ds__extract_quarter', + -- 'acquired_ds__extract_month', + -- 'acquired_ds__extract_day', + -- 'acquired_ds__extract_dow', + -- 'acquired_ds__extract_doy', + -- 'customer_id__acquired_ds__day', + -- 'customer_id__acquired_ds__week', + -- 'customer_id__acquired_ds__month', + -- 'customer_id__acquired_ds__quarter', + -- 'customer_id__acquired_ds__year', + -- 'customer_id__acquired_ds__extract_year', + -- 'customer_id__acquired_ds__extract_quarter', + -- 'customer_id__acquired_ds__extract_month', + -- 'customer_id__acquired_ds__extract_day', + -- 'customer_id__acquired_ds__extract_dow', + -- 'customer_id__acquired_ds__extract_doy', + -- 'customer_third_hop_id__acquired_ds__day', + -- 'customer_third_hop_id__acquired_ds__week', + -- 'customer_third_hop_id__acquired_ds__month', + -- 'customer_third_hop_id__acquired_ds__quarter', + -- 'customer_third_hop_id__acquired_ds__year', + -- 'customer_third_hop_id__acquired_ds__extract_year', + -- 'customer_third_hop_id__acquired_ds__extract_quarter', + -- 'customer_third_hop_id__acquired_ds__extract_month', + -- 'customer_third_hop_id__acquired_ds__extract_day', + -- 'customer_third_hop_id__acquired_ds__extract_dow', + -- 'customer_third_hop_id__acquired_ds__extract_doy', + -- 'metric_time__day', + -- 'metric_time__week', + -- 'metric_time__month', + -- 'metric_time__quarter', + -- 'metric_time__year', + -- 'metric_time__extract_year', + -- 'metric_time__extract_quarter', + -- 'metric_time__extract_month', + -- 'metric_time__extract_day', + -- 'metric_time__extract_dow', + -- 'metric_time__extract_doy', + -- 'customer_id', + -- 'customer_third_hop_id', + -- 'customer_id__customer_third_hop_id', + -- 'customer_third_hop_id__customer_id', + -- ] SELECT - subq_14.account_id__customer_id__customer_third_hop_id - , SUM(subq_14.txn_count) AS txn_count + subq_6.acquired_ds__day + , subq_6.acquired_ds__week + , subq_6.acquired_ds__month + , subq_6.acquired_ds__quarter + , subq_6.acquired_ds__year + , subq_6.acquired_ds__extract_year + , subq_6.acquired_ds__extract_quarter + , subq_6.acquired_ds__extract_month + , subq_6.acquired_ds__extract_day + , subq_6.acquired_ds__extract_dow + , subq_6.acquired_ds__extract_doy + , subq_6.customer_id__acquired_ds__day + , subq_6.customer_id__acquired_ds__week + , subq_6.customer_id__acquired_ds__month + , subq_6.customer_id__acquired_ds__quarter + , subq_6.customer_id__acquired_ds__year + , subq_6.customer_id__acquired_ds__extract_year + , subq_6.customer_id__acquired_ds__extract_quarter + , subq_6.customer_id__acquired_ds__extract_month + , subq_6.customer_id__acquired_ds__extract_day + , subq_6.customer_id__acquired_ds__extract_dow + , subq_6.customer_id__acquired_ds__extract_doy + , subq_6.customer_third_hop_id__acquired_ds__day + , subq_6.customer_third_hop_id__acquired_ds__week + , subq_6.customer_third_hop_id__acquired_ds__month + , subq_6.customer_third_hop_id__acquired_ds__quarter + , subq_6.customer_third_hop_id__acquired_ds__year + , subq_6.customer_third_hop_id__acquired_ds__extract_year + , subq_6.customer_third_hop_id__acquired_ds__extract_quarter + , subq_6.customer_third_hop_id__acquired_ds__extract_month + , subq_6.customer_third_hop_id__acquired_ds__extract_day + , subq_6.customer_third_hop_id__acquired_ds__extract_dow + , subq_6.customer_third_hop_id__acquired_ds__extract_doy + , subq_6.acquired_ds__day AS metric_time__day + , subq_6.acquired_ds__week AS metric_time__week + , subq_6.acquired_ds__month AS metric_time__month + , subq_6.acquired_ds__quarter AS metric_time__quarter + , subq_6.acquired_ds__year AS metric_time__year + , subq_6.acquired_ds__extract_year AS metric_time__extract_year + , subq_6.acquired_ds__extract_quarter AS metric_time__extract_quarter + , subq_6.acquired_ds__extract_month AS metric_time__extract_month + , subq_6.acquired_ds__extract_day AS metric_time__extract_day + , subq_6.acquired_ds__extract_dow AS metric_time__extract_dow + , subq_6.acquired_ds__extract_doy AS metric_time__extract_doy + , subq_6.customer_id + , subq_6.customer_third_hop_id + , subq_6.customer_id__customer_third_hop_id + , subq_6.customer_third_hop_id__customer_id + , subq_6.country + , subq_6.customer_id__country + , subq_6.customer_third_hop_id__country FROM ( - -- Pass Only Elements: ['txn_count', 'account_id__customer_id__customer_third_hop_id'] + -- Read Elements From Semantic Model 'customer_other_data' SELECT - subq_13.account_id__customer_id__customer_third_hop_id - , subq_13.txn_count - FROM ( - -- Join Standard Outputs - SELECT - subq_5.ds_partitioned__day AS ds_partitioned__day - , subq_12.ds_partitioned__day AS account_id__ds_partitioned__day - , subq_5.account_id AS account_id - , subq_12.customer_id__customer_third_hop_id AS account_id__customer_id__customer_third_hop_id - , subq_5.txn_count AS txn_count - FROM ( - -- Pass Only Elements: ['txn_count', 'ds_partitioned__day', 'account_id'] - SELECT - subq_4.ds_partitioned__day - , subq_4.account_id - , subq_4.txn_count - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.account_id__ds_partitioned__day - , subq_3.account_id__ds_partitioned__week - , subq_3.account_id__ds_partitioned__month - , subq_3.account_id__ds_partitioned__quarter - , subq_3.account_id__ds_partitioned__year - , subq_3.account_id__ds_partitioned__extract_year - , subq_3.account_id__ds_partitioned__extract_quarter - , subq_3.account_id__ds_partitioned__extract_month - , subq_3.account_id__ds_partitioned__extract_day - , subq_3.account_id__ds_partitioned__extract_dow - , subq_3.account_id__ds_partitioned__extract_doy - , subq_3.account_id__ds__day - , subq_3.account_id__ds__week - , subq_3.account_id__ds__month - , subq_3.account_id__ds__quarter - , subq_3.account_id__ds__year - , subq_3.account_id__ds__extract_year - , subq_3.account_id__ds__extract_quarter - , subq_3.account_id__ds__extract_month - , subq_3.account_id__ds__extract_day - , subq_3.account_id__ds__extract_dow - , subq_3.account_id__ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.account_id - , subq_3.account_month - , subq_3.account_id__account_month - , subq_3.txn_count - FROM ( - -- Read Elements From Semantic Model 'account_month_txns' - SELECT - account_month_txns_src_22000.txn_count - , DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', account_month_txns_src_22000.ds) AS ds__day - , DATE_TRUNC('week', account_month_txns_src_22000.ds) AS ds__week - , DATE_TRUNC('month', account_month_txns_src_22000.ds) AS ds__month - , DATE_TRUNC('quarter', account_month_txns_src_22000.ds) AS ds__quarter - , DATE_TRUNC('year', account_month_txns_src_22000.ds) AS ds__year - , EXTRACT(year FROM account_month_txns_src_22000.ds) AS ds__extract_year - , EXTRACT(quarter FROM account_month_txns_src_22000.ds) AS ds__extract_quarter - , EXTRACT(month FROM account_month_txns_src_22000.ds) AS ds__extract_month - , EXTRACT(day FROM account_month_txns_src_22000.ds) AS ds__extract_day - , EXTRACT(isodow FROM account_month_txns_src_22000.ds) AS ds__extract_dow - , EXTRACT(doy FROM account_month_txns_src_22000.ds) AS ds__extract_doy - , account_month_txns_src_22000.account_month - , DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__day - , DATE_TRUNC('week', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__week - , DATE_TRUNC('month', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__month - , DATE_TRUNC('quarter', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__quarter - , DATE_TRUNC('year', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__year - , EXTRACT(year FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_year - , EXTRACT(quarter FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_quarter - , EXTRACT(month FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_month - , EXTRACT(day FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_day - , EXTRACT(isodow FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_dow - , EXTRACT(doy FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_doy - , DATE_TRUNC('day', account_month_txns_src_22000.ds) AS account_id__ds__day - , DATE_TRUNC('week', account_month_txns_src_22000.ds) AS account_id__ds__week - , DATE_TRUNC('month', account_month_txns_src_22000.ds) AS account_id__ds__month - , DATE_TRUNC('quarter', account_month_txns_src_22000.ds) AS account_id__ds__quarter - , DATE_TRUNC('year', account_month_txns_src_22000.ds) AS account_id__ds__year - , EXTRACT(year FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_year - , EXTRACT(quarter FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_quarter - , EXTRACT(month FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_month - , EXTRACT(day FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_day - , EXTRACT(isodow FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_dow - , EXTRACT(doy FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_doy - , account_month_txns_src_22000.account_month AS account_id__account_month - , account_month_txns_src_22000.account_id - FROM ***************************.account_month_txns account_month_txns_src_22000 - ) subq_3 - ) subq_4 - ) subq_5 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['ds_partitioned__day', 'account_id', 'customer_id__customer_third_hop_id'] - SELECT - subq_11.ds_partitioned__day - , subq_11.account_id - , subq_11.customer_id__customer_third_hop_id - FROM ( - -- Join Standard Outputs - SELECT - subq_7.ds_partitioned__day AS ds_partitioned__day - , subq_7.ds_partitioned__week AS ds_partitioned__week - , subq_7.ds_partitioned__month AS ds_partitioned__month - , subq_7.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_7.ds_partitioned__year AS ds_partitioned__year - , subq_7.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_7.account_id__ds_partitioned__day AS account_id__ds_partitioned__day - , subq_7.account_id__ds_partitioned__week AS account_id__ds_partitioned__week - , subq_7.account_id__ds_partitioned__month AS account_id__ds_partitioned__month - , subq_7.account_id__ds_partitioned__quarter AS account_id__ds_partitioned__quarter - , subq_7.account_id__ds_partitioned__year AS account_id__ds_partitioned__year - , subq_7.account_id__ds_partitioned__extract_year AS account_id__ds_partitioned__extract_year - , subq_7.account_id__ds_partitioned__extract_quarter AS account_id__ds_partitioned__extract_quarter - , subq_7.account_id__ds_partitioned__extract_month AS account_id__ds_partitioned__extract_month - , subq_7.account_id__ds_partitioned__extract_day AS account_id__ds_partitioned__extract_day - , subq_7.account_id__ds_partitioned__extract_dow AS account_id__ds_partitioned__extract_dow - , subq_7.account_id__ds_partitioned__extract_doy AS account_id__ds_partitioned__extract_doy - , subq_7.bridge_account__ds_partitioned__day AS bridge_account__ds_partitioned__day - , subq_7.bridge_account__ds_partitioned__week AS bridge_account__ds_partitioned__week - , subq_7.bridge_account__ds_partitioned__month AS bridge_account__ds_partitioned__month - , subq_7.bridge_account__ds_partitioned__quarter AS bridge_account__ds_partitioned__quarter - , subq_7.bridge_account__ds_partitioned__year AS bridge_account__ds_partitioned__year - , subq_7.bridge_account__ds_partitioned__extract_year AS bridge_account__ds_partitioned__extract_year - , subq_7.bridge_account__ds_partitioned__extract_quarter AS bridge_account__ds_partitioned__extract_quarter - , subq_7.bridge_account__ds_partitioned__extract_month AS bridge_account__ds_partitioned__extract_month - , subq_7.bridge_account__ds_partitioned__extract_day AS bridge_account__ds_partitioned__extract_day - , subq_7.bridge_account__ds_partitioned__extract_dow AS bridge_account__ds_partitioned__extract_dow - , subq_7.bridge_account__ds_partitioned__extract_doy AS bridge_account__ds_partitioned__extract_doy - , subq_7.metric_time__day AS metric_time__day - , subq_7.metric_time__week AS metric_time__week - , subq_7.metric_time__month AS metric_time__month - , subq_7.metric_time__quarter AS metric_time__quarter - , subq_7.metric_time__year AS metric_time__year - , subq_7.metric_time__extract_year AS metric_time__extract_year - , subq_7.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_7.metric_time__extract_month AS metric_time__extract_month - , 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_10.acquired_ds__day AS customer_id__acquired_ds__day - , subq_10.acquired_ds__week AS customer_id__acquired_ds__week - , subq_10.acquired_ds__month AS customer_id__acquired_ds__month - , subq_10.acquired_ds__quarter AS customer_id__acquired_ds__quarter - , subq_10.acquired_ds__year AS customer_id__acquired_ds__year - , subq_10.acquired_ds__extract_year AS customer_id__acquired_ds__extract_year - , subq_10.acquired_ds__extract_quarter AS customer_id__acquired_ds__extract_quarter - , subq_10.acquired_ds__extract_month AS customer_id__acquired_ds__extract_month - , subq_10.acquired_ds__extract_day AS customer_id__acquired_ds__extract_day - , subq_10.acquired_ds__extract_dow AS customer_id__acquired_ds__extract_dow - , subq_10.acquired_ds__extract_doy AS customer_id__acquired_ds__extract_doy - , subq_10.customer_third_hop_id__acquired_ds__day AS customer_id__customer_third_hop_id__acquired_ds__day - , subq_10.customer_third_hop_id__acquired_ds__week AS customer_id__customer_third_hop_id__acquired_ds__week - , subq_10.customer_third_hop_id__acquired_ds__month AS customer_id__customer_third_hop_id__acquired_ds__month - , subq_10.customer_third_hop_id__acquired_ds__quarter AS customer_id__customer_third_hop_id__acquired_ds__quarter - , subq_10.customer_third_hop_id__acquired_ds__year AS customer_id__customer_third_hop_id__acquired_ds__year - , subq_10.customer_third_hop_id__acquired_ds__extract_year AS customer_id__customer_third_hop_id__acquired_ds__extract_year - , subq_10.customer_third_hop_id__acquired_ds__extract_quarter AS customer_id__customer_third_hop_id__acquired_ds__extract_quarter - , subq_10.customer_third_hop_id__acquired_ds__extract_month AS customer_id__customer_third_hop_id__acquired_ds__extract_month - , subq_10.customer_third_hop_id__acquired_ds__extract_day AS customer_id__customer_third_hop_id__acquired_ds__extract_day - , subq_10.customer_third_hop_id__acquired_ds__extract_dow AS customer_id__customer_third_hop_id__acquired_ds__extract_dow - , subq_10.customer_third_hop_id__acquired_ds__extract_doy AS customer_id__customer_third_hop_id__acquired_ds__extract_doy - , subq_10.metric_time__day AS customer_id__metric_time__day - , subq_10.metric_time__week AS customer_id__metric_time__week - , subq_10.metric_time__month AS customer_id__metric_time__month - , subq_10.metric_time__quarter AS customer_id__metric_time__quarter - , subq_10.metric_time__year AS customer_id__metric_time__year - , subq_10.metric_time__extract_year AS customer_id__metric_time__extract_year - , subq_10.metric_time__extract_quarter AS customer_id__metric_time__extract_quarter - , subq_10.metric_time__extract_month AS customer_id__metric_time__extract_month - , subq_10.metric_time__extract_day AS customer_id__metric_time__extract_day - , subq_10.metric_time__extract_dow AS customer_id__metric_time__extract_dow - , subq_10.metric_time__extract_doy AS customer_id__metric_time__extract_doy - , subq_7.account_id AS account_id - , subq_7.customer_id AS customer_id - , subq_7.account_id__customer_id AS account_id__customer_id - , subq_7.bridge_account__account_id AS bridge_account__account_id - , subq_7.bridge_account__customer_id AS bridge_account__customer_id - , subq_10.customer_third_hop_id AS customer_id__customer_third_hop_id - , subq_10.customer_third_hop_id__customer_id AS customer_id__customer_third_hop_id__customer_id - , subq_7.extra_dim AS extra_dim - , subq_7.account_id__extra_dim AS account_id__extra_dim - , subq_7.bridge_account__extra_dim AS bridge_account__extra_dim - , subq_10.country AS customer_id__country - , subq_10.customer_third_hop_id__country AS customer_id__customer_third_hop_id__country - , subq_7.account_customer_combos AS account_customer_combos - FROM ( - -- Metric Time Dimension 'ds_partitioned' - SELECT - 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.account_id__ds_partitioned__day - , subq_6.account_id__ds_partitioned__week - , subq_6.account_id__ds_partitioned__month - , subq_6.account_id__ds_partitioned__quarter - , subq_6.account_id__ds_partitioned__year - , subq_6.account_id__ds_partitioned__extract_year - , subq_6.account_id__ds_partitioned__extract_quarter - , subq_6.account_id__ds_partitioned__extract_month - , subq_6.account_id__ds_partitioned__extract_day - , subq_6.account_id__ds_partitioned__extract_dow - , subq_6.account_id__ds_partitioned__extract_doy - , subq_6.bridge_account__ds_partitioned__day - , subq_6.bridge_account__ds_partitioned__week - , subq_6.bridge_account__ds_partitioned__month - , subq_6.bridge_account__ds_partitioned__quarter - , subq_6.bridge_account__ds_partitioned__year - , subq_6.bridge_account__ds_partitioned__extract_year - , subq_6.bridge_account__ds_partitioned__extract_quarter - , subq_6.bridge_account__ds_partitioned__extract_month - , subq_6.bridge_account__ds_partitioned__extract_day - , subq_6.bridge_account__ds_partitioned__extract_dow - , subq_6.bridge_account__ds_partitioned__extract_doy - , subq_6.ds_partitioned__day AS metric_time__day - , subq_6.ds_partitioned__week AS metric_time__week - , subq_6.ds_partitioned__month AS metric_time__month - , subq_6.ds_partitioned__quarter AS metric_time__quarter - , subq_6.ds_partitioned__year AS metric_time__year - , subq_6.ds_partitioned__extract_year AS metric_time__extract_year - , subq_6.ds_partitioned__extract_quarter AS metric_time__extract_quarter - , subq_6.ds_partitioned__extract_month AS metric_time__extract_month - , subq_6.ds_partitioned__extract_day AS metric_time__extract_day - , subq_6.ds_partitioned__extract_dow AS metric_time__extract_dow - , subq_6.ds_partitioned__extract_doy AS metric_time__extract_doy - , subq_6.account_id - , subq_6.customer_id - , subq_6.account_id__customer_id - , subq_6.bridge_account__account_id - , subq_6.bridge_account__customer_id - , subq_6.extra_dim - , subq_6.account_id__extra_dim - , subq_6.bridge_account__extra_dim - , subq_6.account_customer_combos - FROM ( - -- Read Elements From Semantic Model 'bridge_table' - SELECT - account_id || customer_id AS account_customer_combos - , bridge_table_src_22000.extra_dim - , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_doy - , bridge_table_src_22000.extra_dim AS account_id__extra_dim - , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_day - , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_doy - , bridge_table_src_22000.extra_dim AS bridge_account__extra_dim - , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_day - , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy - , bridge_table_src_22000.account_id - , bridge_table_src_22000.customer_id - , bridge_table_src_22000.customer_id AS account_id__customer_id - , bridge_table_src_22000.account_id AS bridge_account__account_id - , bridge_table_src_22000.customer_id AS bridge_account__customer_id - FROM ***************************.bridge_table bridge_table_src_22000 - ) subq_6 - ) subq_7 - LEFT OUTER JOIN ( - -- Pass Only Elements: [ - -- 'country', - -- 'customer_id__country', - -- 'customer_third_hop_id__country', - -- 'acquired_ds__day', - -- 'acquired_ds__week', - -- 'acquired_ds__month', - -- 'acquired_ds__quarter', - -- 'acquired_ds__year', - -- 'acquired_ds__extract_year', - -- 'acquired_ds__extract_quarter', - -- 'acquired_ds__extract_month', - -- 'acquired_ds__extract_day', - -- 'acquired_ds__extract_dow', - -- 'acquired_ds__extract_doy', - -- 'customer_id__acquired_ds__day', - -- 'customer_id__acquired_ds__week', - -- 'customer_id__acquired_ds__month', - -- 'customer_id__acquired_ds__quarter', - -- 'customer_id__acquired_ds__year', - -- 'customer_id__acquired_ds__extract_year', - -- 'customer_id__acquired_ds__extract_quarter', - -- 'customer_id__acquired_ds__extract_month', - -- 'customer_id__acquired_ds__extract_day', - -- 'customer_id__acquired_ds__extract_dow', - -- 'customer_id__acquired_ds__extract_doy', - -- 'customer_third_hop_id__acquired_ds__day', - -- 'customer_third_hop_id__acquired_ds__week', - -- 'customer_third_hop_id__acquired_ds__month', - -- 'customer_third_hop_id__acquired_ds__quarter', - -- 'customer_third_hop_id__acquired_ds__year', - -- 'customer_third_hop_id__acquired_ds__extract_year', - -- 'customer_third_hop_id__acquired_ds__extract_quarter', - -- 'customer_third_hop_id__acquired_ds__extract_month', - -- 'customer_third_hop_id__acquired_ds__extract_day', - -- 'customer_third_hop_id__acquired_ds__extract_dow', - -- 'customer_third_hop_id__acquired_ds__extract_doy', - -- 'metric_time__day', - -- 'metric_time__week', - -- 'metric_time__month', - -- 'metric_time__quarter', - -- 'metric_time__year', - -- 'metric_time__extract_year', - -- 'metric_time__extract_quarter', - -- 'metric_time__extract_month', - -- 'metric_time__extract_day', - -- 'metric_time__extract_dow', - -- 'metric_time__extract_doy', - -- 'customer_id', - -- 'customer_third_hop_id', - -- 'customer_id__customer_third_hop_id', - -- 'customer_third_hop_id__customer_id', - -- ] - SELECT - subq_9.acquired_ds__day - , subq_9.acquired_ds__week - , subq_9.acquired_ds__month - , subq_9.acquired_ds__quarter - , subq_9.acquired_ds__year - , subq_9.acquired_ds__extract_year - , subq_9.acquired_ds__extract_quarter - , subq_9.acquired_ds__extract_month - , subq_9.acquired_ds__extract_day - , subq_9.acquired_ds__extract_dow - , subq_9.acquired_ds__extract_doy - , subq_9.customer_id__acquired_ds__day - , subq_9.customer_id__acquired_ds__week - , subq_9.customer_id__acquired_ds__month - , subq_9.customer_id__acquired_ds__quarter - , subq_9.customer_id__acquired_ds__year - , subq_9.customer_id__acquired_ds__extract_year - , subq_9.customer_id__acquired_ds__extract_quarter - , subq_9.customer_id__acquired_ds__extract_month - , subq_9.customer_id__acquired_ds__extract_day - , subq_9.customer_id__acquired_ds__extract_dow - , subq_9.customer_id__acquired_ds__extract_doy - , subq_9.customer_third_hop_id__acquired_ds__day - , subq_9.customer_third_hop_id__acquired_ds__week - , subq_9.customer_third_hop_id__acquired_ds__month - , subq_9.customer_third_hop_id__acquired_ds__quarter - , subq_9.customer_third_hop_id__acquired_ds__year - , subq_9.customer_third_hop_id__acquired_ds__extract_year - , subq_9.customer_third_hop_id__acquired_ds__extract_quarter - , subq_9.customer_third_hop_id__acquired_ds__extract_month - , subq_9.customer_third_hop_id__acquired_ds__extract_day - , subq_9.customer_third_hop_id__acquired_ds__extract_dow - , subq_9.customer_third_hop_id__acquired_ds__extract_doy - , subq_9.metric_time__day - , subq_9.metric_time__week - , subq_9.metric_time__month - , subq_9.metric_time__quarter - , subq_9.metric_time__year - , subq_9.metric_time__extract_year - , subq_9.metric_time__extract_quarter - , subq_9.metric_time__extract_month - , subq_9.metric_time__extract_day - , subq_9.metric_time__extract_dow - , subq_9.metric_time__extract_doy - , subq_9.customer_id - , subq_9.customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id - , subq_9.customer_third_hop_id__customer_id - , subq_9.country - , subq_9.customer_id__country - , subq_9.customer_third_hop_id__country - FROM ( - -- Metric Time Dimension 'acquired_ds' - SELECT - subq_8.acquired_ds__day - , subq_8.acquired_ds__week - , subq_8.acquired_ds__month - , subq_8.acquired_ds__quarter - , subq_8.acquired_ds__year - , subq_8.acquired_ds__extract_year - , subq_8.acquired_ds__extract_quarter - , subq_8.acquired_ds__extract_month - , subq_8.acquired_ds__extract_day - , subq_8.acquired_ds__extract_dow - , subq_8.acquired_ds__extract_doy - , subq_8.customer_id__acquired_ds__day - , subq_8.customer_id__acquired_ds__week - , subq_8.customer_id__acquired_ds__month - , subq_8.customer_id__acquired_ds__quarter - , subq_8.customer_id__acquired_ds__year - , subq_8.customer_id__acquired_ds__extract_year - , subq_8.customer_id__acquired_ds__extract_quarter - , subq_8.customer_id__acquired_ds__extract_month - , subq_8.customer_id__acquired_ds__extract_day - , subq_8.customer_id__acquired_ds__extract_dow - , subq_8.customer_id__acquired_ds__extract_doy - , subq_8.customer_third_hop_id__acquired_ds__day - , subq_8.customer_third_hop_id__acquired_ds__week - , subq_8.customer_third_hop_id__acquired_ds__month - , subq_8.customer_third_hop_id__acquired_ds__quarter - , subq_8.customer_third_hop_id__acquired_ds__year - , subq_8.customer_third_hop_id__acquired_ds__extract_year - , subq_8.customer_third_hop_id__acquired_ds__extract_quarter - , subq_8.customer_third_hop_id__acquired_ds__extract_month - , subq_8.customer_third_hop_id__acquired_ds__extract_day - , subq_8.customer_third_hop_id__acquired_ds__extract_dow - , subq_8.customer_third_hop_id__acquired_ds__extract_doy - , subq_8.acquired_ds__day AS metric_time__day - , subq_8.acquired_ds__week AS metric_time__week - , subq_8.acquired_ds__month AS metric_time__month - , subq_8.acquired_ds__quarter AS metric_time__quarter - , subq_8.acquired_ds__year AS metric_time__year - , subq_8.acquired_ds__extract_year AS metric_time__extract_year - , subq_8.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_8.acquired_ds__extract_month AS metric_time__extract_month - , subq_8.acquired_ds__extract_day AS metric_time__extract_day - , subq_8.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_8.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_8.customer_id - , subq_8.customer_third_hop_id - , subq_8.customer_id__customer_third_hop_id - , subq_8.customer_third_hop_id__customer_id - , subq_8.country - , subq_8.customer_id__country - , subq_8.customer_third_hop_id__country - , subq_8.customers_with_other_data - FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_8 - ) subq_9 - ) subq_10 - ON - subq_7.customer_id = subq_10.customer_id - ) subq_11 - ) subq_12 - ON - ( - subq_5.account_id = subq_12.account_id - ) AND ( - subq_5.ds_partitioned__day = subq_12.ds_partitioned__day - ) - ) subq_13 - ) subq_14 - GROUP BY - subq_14.account_id__customer_id__customer_third_hop_id - ) subq_15 - ) subq_16 - ) subq_17 - ON - subq_2.customer_third_hop_id = subq_17.account_id__customer_id__customer_third_hop_id - ) subq_18 - ) subq_19 - WHERE customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count > 2 - ) subq_20 - ) subq_21 -) subq_22 + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_6 + ) subq_7 + ON + subq_5.customer_id = subq_7.customer_id + ) subq_8 + ON + ( + subq_3.account_id = subq_8.account_id + ) AND ( + subq_3.ds_partitioned__day = subq_8.ds_partitioned__day + ) + ) subq_9 + GROUP BY + subq_9.account_id__customer_id__customer_third_hop_id + ) subq_10 + ) subq_11 + ON + subq_1.customer_third_hop_id = subq_11.account_id__customer_id__customer_third_hop_id + ) subq_12 + WHERE customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count > 2 + ) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_multi_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_multi_hop__plan0_optimized.sql index 97117da92a..f0849eef18 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_multi_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_multi_hop__plan0_optimized.sql @@ -1,49 +1,12 @@ +-- Read Elements From Semantic Model 'third_hop_table' +-- Metric Time Dimension 'third_hop_ds' +-- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] +-- Join Standard Outputs +-- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count'] -- Constrain Output with WHERE -- Pass Only Elements: ['third_hop_count',] -- Aggregate Measures -- Compute Metrics via Expressions SELECT - COUNT(DISTINCT third_hop_count) AS third_hop_count -FROM ( - -- Join Standard Outputs - -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count'] - SELECT - subq_40.account_id__customer_id__customer_third_hop_id__txn_count AS customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count - , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count - FROM ***************************.third_hop_table third_hop_table_src_22000 - LEFT OUTER JOIN ( - -- Join Standard Outputs - -- Pass Only Elements: ['txn_count', 'account_id__customer_id__customer_third_hop_id'] - -- Aggregate Measures - -- Compute Metrics via Expressions - -- Pass Only Elements: ['account_id__customer_id__customer_third_hop_id', 'account_id__customer_id__customer_third_hop_id__txn_count'] - SELECT - subq_35.customer_id__customer_third_hop_id AS account_id__customer_id__customer_third_hop_id - , SUM(account_month_txns_src_22000.txn_count) AS account_id__customer_id__customer_third_hop_id__txn_count - FROM ***************************.account_month_txns account_month_txns_src_22000 - LEFT OUTER JOIN ( - -- Join Standard Outputs - -- Pass Only Elements: ['ds_partitioned__day', 'account_id', 'customer_id__customer_third_hop_id'] - SELECT - DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__day - , bridge_table_src_22000.account_id AS account_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - FROM ***************************.bridge_table bridge_table_src_22000 - LEFT OUTER JOIN - ***************************.customer_other_data customer_other_data_src_22000 - ON - bridge_table_src_22000.customer_id = customer_other_data_src_22000.customer_id - ) subq_35 - ON - ( - account_month_txns_src_22000.account_id = subq_35.account_id - ) AND ( - DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) = subq_35.ds_partitioned__day - ) - GROUP BY - subq_35.customer_id__customer_third_hop_id - ) subq_40 - ON - third_hop_table_src_22000.customer_third_hop_id = subq_40.account_id__customer_id__customer_third_hop_id -) subq_42 -WHERE customer_third_hop_id__account_id__customer_id__customer_third_hop_id__txn_count > 2 + COUNT(DISTINCT customer_third_hop_id) AS third_hop_count +FROM ***************************.third_hop_table third_hop_table_src_22000 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql index aa1fbcf12d..679cad23ba 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0.sql @@ -1,257 +1,138 @@ -- Compute Metrics via Expressions SELECT - subq_15.third_hop_count + subq_9.third_hop_count FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_14.third_hop_count) AS third_hop_count + COUNT(DISTINCT subq_8.third_hop_count) AS third_hop_count FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['third_hop_count',] SELECT - subq_13.third_hop_count + subq_7.third_hop_count FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_12.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_12.third_hop_count + subq_1.third_hop_count AS third_hop_count FROM ( - -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] + -- Metric Time Dimension 'third_hop_ds' + -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] SELECT - subq_11.customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_11.third_hop_count + subq_0.customer_third_hop_id + , subq_0.third_hop_count FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'third_hop_table' SELECT - subq_2.customer_third_hop_id AS customer_third_hop_id - , subq_10.customer_id__customer_third_hop_id AS customer_third_hop_id__customer_id__customer_third_hop_id - , subq_10.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , subq_2.third_hop_count AS third_hop_count + third_hop_table_src_22000.customer_third_hop_id AS third_hop_count + , third_hop_table_src_22000.value + , DATE_TRUNC('day', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__day + , DATE_TRUNC('week', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__week + , DATE_TRUNC('month', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__month + , DATE_TRUNC('quarter', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__quarter + , DATE_TRUNC('year', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__year + , EXTRACT(year FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_year + , EXTRACT(quarter FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_quarter + , EXTRACT(month FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_month + , EXTRACT(day FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_day + , EXTRACT(isodow FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_dow + , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_doy + , third_hop_table_src_22000.value AS customer_third_hop_id__value + , DATE_TRUNC('day', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__day + , DATE_TRUNC('week', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__week + , DATE_TRUNC('month', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__month + , DATE_TRUNC('quarter', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__quarter + , DATE_TRUNC('year', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__year + , EXTRACT(year FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_year + , EXTRACT(quarter FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_quarter + , EXTRACT(month FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_month + , EXTRACT(day FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_day + , EXTRACT(isodow FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_dow + , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy + , third_hop_table_src_22000.customer_third_hop_id + FROM ***************************.third_hop_table third_hop_table_src_22000 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] + SELECT + subq_5.customer_id__customer_third_hop_id + , subq_5.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + FROM ( + -- Aggregate Measures + SELECT + subq_4.customer_id__customer_third_hop_id + , SUM(subq_4.customers_with_other_data) AS customers_with_other_data FROM ( - -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id'] - SELECT - subq_1.customer_third_hop_id - , subq_1.third_hop_count - FROM ( - -- Metric Time Dimension 'third_hop_ds' - SELECT - subq_0.third_hop_ds__day - , subq_0.third_hop_ds__week - , subq_0.third_hop_ds__month - , subq_0.third_hop_ds__quarter - , subq_0.third_hop_ds__year - , subq_0.third_hop_ds__extract_year - , subq_0.third_hop_ds__extract_quarter - , subq_0.third_hop_ds__extract_month - , subq_0.third_hop_ds__extract_day - , subq_0.third_hop_ds__extract_dow - , subq_0.third_hop_ds__extract_doy - , subq_0.customer_third_hop_id__third_hop_ds__day - , subq_0.customer_third_hop_id__third_hop_ds__week - , subq_0.customer_third_hop_id__third_hop_ds__month - , subq_0.customer_third_hop_id__third_hop_ds__quarter - , subq_0.customer_third_hop_id__third_hop_ds__year - , subq_0.customer_third_hop_id__third_hop_ds__extract_year - , subq_0.customer_third_hop_id__third_hop_ds__extract_quarter - , subq_0.customer_third_hop_id__third_hop_ds__extract_month - , subq_0.customer_third_hop_id__third_hop_ds__extract_day - , subq_0.customer_third_hop_id__third_hop_ds__extract_dow - , subq_0.customer_third_hop_id__third_hop_ds__extract_doy - , subq_0.third_hop_ds__day AS metric_time__day - , subq_0.third_hop_ds__week AS metric_time__week - , subq_0.third_hop_ds__month AS metric_time__month - , subq_0.third_hop_ds__quarter AS metric_time__quarter - , subq_0.third_hop_ds__year AS metric_time__year - , subq_0.third_hop_ds__extract_year AS metric_time__extract_year - , subq_0.third_hop_ds__extract_quarter AS metric_time__extract_quarter - , subq_0.third_hop_ds__extract_month AS metric_time__extract_month - , subq_0.third_hop_ds__extract_day AS metric_time__extract_day - , subq_0.third_hop_ds__extract_dow AS metric_time__extract_dow - , subq_0.third_hop_ds__extract_doy AS metric_time__extract_doy - , subq_0.customer_third_hop_id - , subq_0.value - , subq_0.customer_third_hop_id__value - , subq_0.third_hop_count - FROM ( - -- Read Elements From Semantic Model 'third_hop_table' - SELECT - third_hop_table_src_22000.customer_third_hop_id AS third_hop_count - , third_hop_table_src_22000.value - , DATE_TRUNC('day', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__day - , DATE_TRUNC('week', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__week - , DATE_TRUNC('month', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__month - , DATE_TRUNC('quarter', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__quarter - , DATE_TRUNC('year', third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__year - , EXTRACT(year FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_year - , EXTRACT(quarter FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_quarter - , EXTRACT(month FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_month - , EXTRACT(day FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_day - , EXTRACT(isodow FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_dow - , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS third_hop_ds__extract_doy - , third_hop_table_src_22000.value AS customer_third_hop_id__value - , DATE_TRUNC('day', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__day - , DATE_TRUNC('week', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__week - , DATE_TRUNC('month', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__month - , DATE_TRUNC('quarter', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__quarter - , DATE_TRUNC('year', third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__year - , EXTRACT(year FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_year - , EXTRACT(quarter FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_quarter - , EXTRACT(month FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_month - , EXTRACT(day FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_day - , EXTRACT(isodow FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_dow - , EXTRACT(doy FROM third_hop_table_src_22000.third_hop_ds) AS customer_third_hop_id__third_hop_ds__extract_doy - , third_hop_table_src_22000.customer_third_hop_id - FROM ***************************.third_hop_table third_hop_table_src_22000 - ) subq_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] + -- Constrain Output with WHERE + -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] SELECT - subq_9.customer_id__customer_third_hop_id - , subq_9.customer_id__customer_third_hop_id__paraguayan_customers + subq_3.customer_id__customer_third_hop_id + , subq_3.customers_with_other_data FROM ( - -- Compute Metrics via Expressions + -- Metric Time Dimension 'acquired_ds' + -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] SELECT - subq_8.customer_id__customer_third_hop_id - , subq_8.customers_with_other_data AS customer_id__customer_third_hop_id__paraguayan_customers + subq_2.customer_id__customer_third_hop_id + , subq_2.customer_id__country + , subq_2.customers_with_other_data FROM ( - -- Aggregate Measures + -- Read Elements From Semantic Model 'customer_other_data' SELECT - subq_7.customer_id__customer_third_hop_id - , SUM(subq_7.customers_with_other_data) AS customers_with_other_data - FROM ( - -- Pass Only Elements: ['customers_with_other_data', 'customer_id__customer_third_hop_id'] - SELECT - subq_6.customer_id__customer_third_hop_id - , subq_6.customers_with_other_data - FROM ( - -- Constrain Output with WHERE - SELECT - subq_5.customer_id__customer_third_hop_id - , subq_5.customer_id__country - , subq_5.customers_with_other_data - FROM ( - -- Pass Only Elements: ['customers_with_other_data', 'customer_id__country', 'customer_id__customer_third_hop_id'] - SELECT - subq_4.customer_id__customer_third_hop_id - , subq_4.customer_id__country - , subq_4.customers_with_other_data - FROM ( - -- Metric Time Dimension 'acquired_ds' - SELECT - subq_3.acquired_ds__day - , subq_3.acquired_ds__week - , subq_3.acquired_ds__month - , subq_3.acquired_ds__quarter - , subq_3.acquired_ds__year - , subq_3.acquired_ds__extract_year - , subq_3.acquired_ds__extract_quarter - , subq_3.acquired_ds__extract_month - , subq_3.acquired_ds__extract_day - , subq_3.acquired_ds__extract_dow - , subq_3.acquired_ds__extract_doy - , subq_3.customer_id__acquired_ds__day - , subq_3.customer_id__acquired_ds__week - , subq_3.customer_id__acquired_ds__month - , subq_3.customer_id__acquired_ds__quarter - , subq_3.customer_id__acquired_ds__year - , subq_3.customer_id__acquired_ds__extract_year - , subq_3.customer_id__acquired_ds__extract_quarter - , subq_3.customer_id__acquired_ds__extract_month - , subq_3.customer_id__acquired_ds__extract_day - , subq_3.customer_id__acquired_ds__extract_dow - , subq_3.customer_id__acquired_ds__extract_doy - , subq_3.customer_third_hop_id__acquired_ds__day - , subq_3.customer_third_hop_id__acquired_ds__week - , subq_3.customer_third_hop_id__acquired_ds__month - , subq_3.customer_third_hop_id__acquired_ds__quarter - , subq_3.customer_third_hop_id__acquired_ds__year - , subq_3.customer_third_hop_id__acquired_ds__extract_year - , subq_3.customer_third_hop_id__acquired_ds__extract_quarter - , subq_3.customer_third_hop_id__acquired_ds__extract_month - , subq_3.customer_third_hop_id__acquired_ds__extract_day - , subq_3.customer_third_hop_id__acquired_ds__extract_dow - , subq_3.customer_third_hop_id__acquired_ds__extract_doy - , subq_3.acquired_ds__day AS metric_time__day - , subq_3.acquired_ds__week AS metric_time__week - , subq_3.acquired_ds__month AS metric_time__month - , subq_3.acquired_ds__quarter AS metric_time__quarter - , subq_3.acquired_ds__year AS metric_time__year - , subq_3.acquired_ds__extract_year AS metric_time__extract_year - , subq_3.acquired_ds__extract_quarter AS metric_time__extract_quarter - , subq_3.acquired_ds__extract_month AS metric_time__extract_month - , subq_3.acquired_ds__extract_day AS metric_time__extract_day - , subq_3.acquired_ds__extract_dow AS metric_time__extract_dow - , subq_3.acquired_ds__extract_doy AS metric_time__extract_doy - , subq_3.customer_id - , subq_3.customer_third_hop_id - , subq_3.customer_id__customer_third_hop_id - , subq_3.customer_third_hop_id__customer_id - , subq_3.country - , subq_3.customer_id__country - , subq_3.customer_third_hop_id__country - , subq_3.customers_with_other_data - FROM ( - -- Read Elements From Semantic Model 'customer_other_data' - SELECT - 1 AS customers_with_other_data - , customer_other_data_src_22000.country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy - , customer_other_data_src_22000.country AS customer_third_hop_id__country - , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day - , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week - , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month - , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter - , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year - , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year - , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter - , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month - , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day - , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow - , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy - , customer_other_data_src_22000.customer_id - , customer_other_data_src_22000.customer_third_hop_id - , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id - , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id - FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_3 - ) subq_4 - ) subq_5 - WHERE customer_id__country = 'paraguay' - ) subq_6 - ) subq_7 - GROUP BY - subq_7.customer_id__customer_third_hop_id - ) subq_8 - ) subq_9 - ) subq_10 - ON - subq_2.customer_third_hop_id = subq_10.customer_id__customer_third_hop_id - ) subq_11 - ) subq_12 - WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 - ) subq_13 - ) subq_14 -) subq_15 + 1 AS customers_with_other_data + , customer_other_data_src_22000.country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_id__acquired_ds__extract_doy + , customer_other_data_src_22000.country AS customer_third_hop_id__country + , DATE_TRUNC('day', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__day + , DATE_TRUNC('week', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__week + , DATE_TRUNC('month', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__month + , DATE_TRUNC('quarter', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__quarter + , DATE_TRUNC('year', customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__year + , EXTRACT(year FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_year + , EXTRACT(quarter FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_quarter + , EXTRACT(month FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_month + , EXTRACT(day FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_day + , EXTRACT(isodow FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_dow + , EXTRACT(doy FROM customer_other_data_src_22000.acquired_ds) AS customer_third_hop_id__acquired_ds__extract_doy + , customer_other_data_src_22000.customer_id + , customer_other_data_src_22000.customer_third_hop_id + , customer_other_data_src_22000.customer_third_hop_id AS customer_id__customer_third_hop_id + , customer_other_data_src_22000.customer_id AS customer_third_hop_id__customer_id + FROM ***************************.customer_other_data customer_other_data_src_22000 + ) subq_2 + ) subq_3 + WHERE customer_id__country = 'paraguay' + ) subq_4 + GROUP BY + subq_4.customer_id__customer_third_hop_id + ) subq_5 + ) subq_6 + ON + subq_1.customer_third_hop_id = subq_6.customer_id__customer_third_hop_id + ) subq_7 + WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql index 803f2dc0b1..b4c1586958 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_inner_query_single_hop__plan0_optimized.sql @@ -8,8 +8,7 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['third_hop_count', 'customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers'] SELECT - subq_26.customer_id__customer_third_hop_id__paraguayan_customers AS customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers - , third_hop_table_src_22000.customer_third_hop_id AS third_hop_count + third_hop_table_src_22000.customer_third_hop_id AS third_hop_count FROM ***************************.third_hop_table third_hop_table_src_22000 LEFT OUTER JOIN ( -- Constrain Output with WHERE @@ -19,7 +18,6 @@ FROM ( -- Pass Only Elements: ['customer_id__customer_third_hop_id', 'customer_id__customer_third_hop_id__paraguayan_customers'] SELECT customer_id__customer_third_hop_id - , SUM(customers_with_other_data) AS customer_id__customer_third_hop_id__paraguayan_customers FROM ( -- Read Elements From Semantic Model 'customer_other_data' -- Metric Time Dimension 'acquired_ds' @@ -27,14 +25,13 @@ FROM ( SELECT customer_third_hop_id AS customer_id__customer_third_hop_id , country AS customer_id__country - , 1 AS customers_with_other_data FROM ***************************.customer_other_data customer_other_data_src_22000 - ) subq_21 + ) subq_13 WHERE customer_id__country = 'paraguay' GROUP BY customer_id__customer_third_hop_id - ) subq_26 + ) subq_16 ON - third_hop_table_src_22000.customer_third_hop_id = subq_26.customer_id__customer_third_hop_id -) subq_28 + third_hop_table_src_22000.customer_third_hop_id = subq_16.customer_id__customer_third_hop_id +) subq_17 WHERE customer_third_hop_id__customer_id__customer_third_hop_id__paraguayan_customers > 0 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0.sql index c22561e2a0..6eb0a59d59 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0.sql @@ -1,457 +1,239 @@ -- Compute Metrics via Expressions SELECT - subq_13.bookers + subq_8.bookers FROM ( -- Aggregate Measures SELECT - COUNT(DISTINCT subq_12.bookers) AS bookers + COUNT(DISTINCT subq_7.bookers) AS bookers FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookers',] SELECT - subq_11.bookers + subq_6.bookers FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookers', 'listing__bookers'] SELECT - subq_10.listing__bookers - , subq_10.bookers + subq_5.listing__bookers AS listing__bookers + , subq_1.bookers AS bookers FROM ( - -- Pass Only Elements: ['bookers', 'listing__bookers'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'listing'] SELECT - subq_9.listing__bookers - , subq_9.bookers + subq_0.listing + , subq_0.bookers FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.listing AS listing - , subq_8.listing__bookers AS listing__bookers - , subq_2.bookers AS bookers + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing', 'listing__bookers'] + SELECT + subq_4.listing + , subq_4.bookers AS listing__bookers + FROM ( + -- Aggregate Measures + SELECT + subq_3.listing + , COUNT(DISTINCT subq_3.bookers) AS bookers FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookers', 'listing'] SELECT - subq_1.listing - , subq_1.bookers - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'listing__bookers'] - SELECT - subq_7.listing - , subq_7.listing__bookers + subq_2.listing + , subq_2.bookers FROM ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_6.listing - , subq_6.bookers AS listing__bookers - FROM ( - -- Aggregate Measures - SELECT - subq_5.listing - , COUNT(DISTINCT subq_5.bookers) AS bookers - FROM ( - -- Pass Only Elements: ['bookers', 'listing'] - SELECT - subq_4.listing - , subq_4.bookers - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.paid_at__day - , subq_3.paid_at__week - , subq_3.paid_at__month - , subq_3.paid_at__quarter - , subq_3.paid_at__year - , subq_3.paid_at__extract_year - , subq_3.paid_at__extract_quarter - , subq_3.paid_at__extract_month - , subq_3.paid_at__extract_day - , subq_3.paid_at__extract_dow - , subq_3.paid_at__extract_doy - , subq_3.booking__ds__day - , subq_3.booking__ds__week - , subq_3.booking__ds__month - , subq_3.booking__ds__quarter - , subq_3.booking__ds__year - , subq_3.booking__ds__extract_year - , subq_3.booking__ds__extract_quarter - , subq_3.booking__ds__extract_month - , subq_3.booking__ds__extract_day - , subq_3.booking__ds__extract_dow - , subq_3.booking__ds__extract_doy - , subq_3.booking__ds_partitioned__day - , subq_3.booking__ds_partitioned__week - , subq_3.booking__ds_partitioned__month - , subq_3.booking__ds_partitioned__quarter - , subq_3.booking__ds_partitioned__year - , subq_3.booking__ds_partitioned__extract_year - , subq_3.booking__ds_partitioned__extract_quarter - , subq_3.booking__ds_partitioned__extract_month - , subq_3.booking__ds_partitioned__extract_day - , subq_3.booking__ds_partitioned__extract_dow - , subq_3.booking__ds_partitioned__extract_doy - , subq_3.booking__paid_at__day - , subq_3.booking__paid_at__week - , subq_3.booking__paid_at__month - , subq_3.booking__paid_at__quarter - , subq_3.booking__paid_at__year - , subq_3.booking__paid_at__extract_year - , subq_3.booking__paid_at__extract_quarter - , subq_3.booking__paid_at__extract_month - , subq_3.booking__paid_at__extract_day - , subq_3.booking__paid_at__extract_dow - , subq_3.booking__paid_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.guest - , subq_3.host - , subq_3.booking__listing - , subq_3.booking__guest - , subq_3.booking__host - , subq_3.is_instant - , subq_3.booking__is_instant - , subq_3.bookings - , subq_3.instant_bookings - , subq_3.booking_value - , subq_3.max_booking_value - , subq_3.min_booking_value - , subq_3.bookers - , subq_3.average_booking_value - , subq_3.referred_bookings - , subq_3.median_booking_value - , subq_3.booking_value_p99 - , subq_3.discrete_booking_value_p99 - , subq_3.approximate_continuous_booking_value_p99 - , subq_3.approximate_discrete_booking_value_p99 - 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_3 - ) subq_4 - ) subq_5 - GROUP BY - subq_5.listing - ) subq_6 - ) subq_7 - ) subq_8 - ON - subq_2.listing = subq_8.listing - ) subq_9 - ) subq_10 - WHERE listing__bookers > 1.00 - ) subq_11 - ) subq_12 -) subq_13 + 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_2 + ) subq_3 + GROUP BY + subq_3.listing + ) subq_4 + ) subq_5 + ON + subq_1.listing = subq_5.listing + ) subq_6 + WHERE listing__bookers > 1.00 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0_optimized.sql index fc6f75f09e..11ae538da6 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_filtered_by_itself__plan0_optimized.sql @@ -8,8 +8,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookers', 'listing__bookers'] SELECT - subq_22.listing__bookers AS listing__bookers - , subq_16.bookers AS bookers + subq_14.listing__bookers AS listing__bookers + , subq_10.bookers AS bookers FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -18,7 +18,7 @@ FROM ( listing_id AS listing , guest_id AS bookers FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_16 + ) subq_10 LEFT OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -32,8 +32,8 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY listing_id - ) subq_22 + ) subq_14 ON - subq_16.listing = subq_22.listing -) subq_24 + subq_10.listing = subq_14.listing +) subq_15 WHERE listing__bookers > 1.00 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0.sql index 35bfbe44c8..b9c67417f2 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0.sql @@ -1,403 +1,214 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.listings AS active_listings + subq_8.metric_time__day + , subq_8.listings AS active_listings FROM ( -- Aggregate Measures SELECT - subq_12.metric_time__day - , SUM(subq_12.listings) AS listings + subq_7.metric_time__day + , SUM(subq_7.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings', 'metric_time__day'] SELECT - subq_11.metric_time__day - , subq_11.listings + subq_6.metric_time__day + , subq_6.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'metric_time__day', 'listing__bookings'] SELECT - subq_10.metric_time__day - , subq_10.listing__bookings - , subq_10.listings + subq_1.metric_time__day AS metric_time__day + , subq_5.listing__bookings AS listing__bookings + , subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'metric_time__day', 'listing__bookings'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'metric_time__day', 'listing'] SELECT - subq_9.metric_time__day - , subq_9.listing__bookings - , subq_9.listings + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_8.listing__bookings AS listing__bookings - , subq_2.listings AS listings + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing', 'listing__bookings'] + SELECT + subq_4.listing + , subq_4.bookings AS listing__bookings + FROM ( + -- Aggregate Measures + SELECT + subq_3.listing + , SUM(subq_3.bookings) AS bookings FROM ( - -- Pass Only Elements: ['listings', 'metric_time__day', 'listing'] - SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.listings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'listing__bookings'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'listing'] SELECT - subq_7.listing - , subq_7.listing__bookings + subq_2.listing + , subq_2.bookings FROM ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_6.listing - , subq_6.bookings AS listing__bookings - FROM ( - -- Aggregate Measures - SELECT - subq_5.listing - , SUM(subq_5.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'listing'] - SELECT - subq_4.listing - , subq_4.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.paid_at__day - , subq_3.paid_at__week - , subq_3.paid_at__month - , subq_3.paid_at__quarter - , subq_3.paid_at__year - , subq_3.paid_at__extract_year - , subq_3.paid_at__extract_quarter - , subq_3.paid_at__extract_month - , subq_3.paid_at__extract_day - , subq_3.paid_at__extract_dow - , subq_3.paid_at__extract_doy - , subq_3.booking__ds__day - , subq_3.booking__ds__week - , subq_3.booking__ds__month - , subq_3.booking__ds__quarter - , subq_3.booking__ds__year - , subq_3.booking__ds__extract_year - , subq_3.booking__ds__extract_quarter - , subq_3.booking__ds__extract_month - , subq_3.booking__ds__extract_day - , subq_3.booking__ds__extract_dow - , subq_3.booking__ds__extract_doy - , subq_3.booking__ds_partitioned__day - , subq_3.booking__ds_partitioned__week - , subq_3.booking__ds_partitioned__month - , subq_3.booking__ds_partitioned__quarter - , subq_3.booking__ds_partitioned__year - , subq_3.booking__ds_partitioned__extract_year - , subq_3.booking__ds_partitioned__extract_quarter - , subq_3.booking__ds_partitioned__extract_month - , subq_3.booking__ds_partitioned__extract_day - , subq_3.booking__ds_partitioned__extract_dow - , subq_3.booking__ds_partitioned__extract_doy - , subq_3.booking__paid_at__day - , subq_3.booking__paid_at__week - , subq_3.booking__paid_at__month - , subq_3.booking__paid_at__quarter - , subq_3.booking__paid_at__year - , subq_3.booking__paid_at__extract_year - , subq_3.booking__paid_at__extract_quarter - , subq_3.booking__paid_at__extract_month - , subq_3.booking__paid_at__extract_day - , subq_3.booking__paid_at__extract_dow - , subq_3.booking__paid_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.guest - , subq_3.host - , subq_3.booking__listing - , subq_3.booking__guest - , subq_3.booking__host - , subq_3.is_instant - , subq_3.booking__is_instant - , subq_3.bookings - , subq_3.instant_bookings - , subq_3.booking_value - , subq_3.max_booking_value - , subq_3.min_booking_value - , subq_3.bookers - , subq_3.average_booking_value - , subq_3.referred_bookings - , subq_3.median_booking_value - , subq_3.booking_value_p99 - , subq_3.discrete_booking_value_p99 - , subq_3.approximate_continuous_booking_value_p99 - , subq_3.approximate_discrete_booking_value_p99 - 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_3 - ) subq_4 - ) subq_5 - GROUP BY - subq_5.listing - ) subq_6 - ) subq_7 - ) subq_8 - ON - subq_2.listing = subq_8.listing - ) subq_9 - ) subq_10 - WHERE listing__bookings > 2 - ) subq_11 - ) subq_12 + 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_2 + ) subq_3 + GROUP BY + subq_3.listing + ) subq_4 + ) subq_5 + ON + subq_1.listing = subq_5.listing + ) subq_6 + WHERE listing__bookings > 2 + ) subq_7 GROUP BY - subq_12.metric_time__day -) subq_13 + subq_7.metric_time__day +) subq_8 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0_optimized.sql index 21fd1f7db3..477e945ffc 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_metric_in_where_filter__plan0_optimized.sql @@ -9,9 +9,9 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['listings', 'metric_time__day', 'listing__bookings'] SELECT - subq_16.metric_time__day AS metric_time__day - , subq_22.listing__bookings AS listing__bookings - , subq_16.listings AS listings + subq_10.metric_time__day AS metric_time__day + , subq_14.listing__bookings AS listing__bookings + , subq_10.listings AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -21,7 +21,7 @@ FROM ( , listing_id AS listing , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_16 + ) subq_10 LEFT OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -37,13 +37,13 @@ FROM ( listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_19 + ) subq_12 GROUP BY listing - ) subq_22 + ) subq_14 ON - subq_16.listing = subq_22.listing -) subq_24 + subq_10.listing = subq_14.listing +) subq_15 WHERE listing__bookings > 2 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0.sql index 5e05e63f8a..576d47cf2b 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0.sql @@ -1,269 +1,144 @@ -- Compute Metrics via Expressions SELECT - subq_13.listings + subq_8.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_12.listings) AS listings + SUM(subq_7.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings',] SELECT - subq_11.listings + subq_6.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__revenue_all_time'] SELECT - subq_10.user__revenue_all_time - , subq_10.listings + subq_5.user__revenue_all_time AS user__revenue_all_time + , subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'user__revenue_all_time'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'user'] SELECT - subq_9.user__revenue_all_time - , subq_9.listings + subq_0.user + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.user AS user - , subq_8.user__revenue_all_time AS user__revenue_all_time - , subq_2.listings AS listings + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['user', 'user__revenue_all_time'] + SELECT + subq_4.user + , subq_4.txn_revenue AS user__revenue_all_time + FROM ( + -- Aggregate Measures + SELECT + subq_3.user + , SUM(subq_3.txn_revenue) AS txn_revenue FROM ( - -- Pass Only Elements: ['listings', 'user'] - SELECT - subq_1.user - , subq_1.listings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['user', 'user__revenue_all_time'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['txn_revenue', 'user'] SELECT - subq_7.user - , subq_7.user__revenue_all_time + subq_2.user + , subq_2.txn_revenue FROM ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'revenue' SELECT - subq_6.user - , subq_6.txn_revenue AS user__revenue_all_time - FROM ( - -- Aggregate Measures - SELECT - subq_5.user - , SUM(subq_5.txn_revenue) AS txn_revenue - FROM ( - -- Pass Only Elements: ['txn_revenue', 'user'] - SELECT - subq_4.user - , subq_4.txn_revenue - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.revenue_instance__ds__day - , subq_3.revenue_instance__ds__week - , subq_3.revenue_instance__ds__month - , subq_3.revenue_instance__ds__quarter - , subq_3.revenue_instance__ds__year - , subq_3.revenue_instance__ds__extract_year - , subq_3.revenue_instance__ds__extract_quarter - , subq_3.revenue_instance__ds__extract_month - , subq_3.revenue_instance__ds__extract_day - , subq_3.revenue_instance__ds__extract_dow - , subq_3.revenue_instance__ds__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.user - , subq_3.revenue_instance__user - , subq_3.txn_revenue - FROM ( - -- Read Elements From Semantic Model 'revenue' - SELECT - revenue_src_28000.revenue AS txn_revenue - , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day - , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week - , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month - , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter - , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year - , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year - , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter - , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month - , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day - , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow - , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy - , revenue_src_28000.user_id AS user - , revenue_src_28000.user_id AS revenue_instance__user - FROM ***************************.fct_revenue revenue_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 - GROUP BY - subq_5.user - ) subq_6 - ) subq_7 - ) subq_8 - ON - subq_2.user = subq_8.user - ) subq_9 - ) subq_10 - WHERE user__revenue_all_time > 1 - ) subq_11 - ) subq_12 -) subq_13 + revenue_src_28000.revenue AS txn_revenue + , DATE_TRUNC('day', revenue_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', revenue_src_28000.created_at) AS revenue_instance__ds__day + , DATE_TRUNC('week', revenue_src_28000.created_at) AS revenue_instance__ds__week + , DATE_TRUNC('month', revenue_src_28000.created_at) AS revenue_instance__ds__month + , DATE_TRUNC('quarter', revenue_src_28000.created_at) AS revenue_instance__ds__quarter + , DATE_TRUNC('year', revenue_src_28000.created_at) AS revenue_instance__ds__year + , EXTRACT(year FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_year + , EXTRACT(quarter FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_quarter + , EXTRACT(month FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_month + , EXTRACT(day FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_day + , EXTRACT(isodow FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_dow + , EXTRACT(doy FROM revenue_src_28000.created_at) AS revenue_instance__ds__extract_doy + , revenue_src_28000.user_id AS user + , revenue_src_28000.user_id AS revenue_instance__user + FROM ***************************.fct_revenue revenue_src_28000 + ) subq_2 + ) subq_3 + GROUP BY + subq_3.user + ) subq_4 + ) subq_5 + ON + subq_1.user = subq_5.user + ) subq_6 + WHERE user__revenue_all_time > 1 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0_optimized.sql index 2b782589e8..8c691c4b43 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_cumulative_metric_in_where_filter__plan0_optimized.sql @@ -8,8 +8,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['listings', 'user__revenue_all_time'] SELECT - subq_22.user__revenue_all_time AS user__revenue_all_time - , subq_16.listings AS listings + subq_14.user__revenue_all_time AS user__revenue_all_time + , subq_10.listings AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -18,7 +18,7 @@ FROM ( user_id AS user , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_16 + ) subq_10 LEFT OUTER JOIN ( -- Read Elements From Semantic Model 'revenue' -- Metric Time Dimension 'ds' @@ -32,8 +32,8 @@ FROM ( FROM ***************************.fct_revenue revenue_src_28000 GROUP BY user_id - ) subq_22 + ) subq_14 ON - subq_16.user = subq_22.user -) subq_24 + subq_10.user = subq_14.user +) subq_15 WHERE user__revenue_all_time > 1 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0.sql index b4b77786c8..71a4d69abd 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0.sql @@ -1,549 +1,299 @@ -- Compute Metrics via Expressions SELECT - subq_20.listings + subq_14.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_19.listings) AS listings + SUM(subq_13.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings',] SELECT - subq_18.listings + subq_12.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'listing__views_times_booking_value'] SELECT - subq_17.listing__views_times_booking_value - , subq_17.listings + subq_11.listing__views_times_booking_value AS listing__views_times_booking_value + , subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'listing__views_times_booking_value'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'listing'] SELECT - subq_16.listing__views_times_booking_value - , subq_16.listings + subq_0.listing + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.listing AS listing - , subq_15.listing__views_times_booking_value AS listing__views_times_booking_value - , subq_2.listings AS listings + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing', 'listing__views_times_booking_value'] + SELECT + subq_10.listing + , booking_value * views AS listing__views_times_booking_value + FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_5.listing, subq_9.listing) AS listing + , MAX(subq_5.booking_value) AS booking_value + , MAX(subq_9.views) AS views FROM ( - -- Pass Only Elements: ['listings', 'listing'] + -- Compute Metrics via Expressions SELECT - subq_1.listing - , subq_1.listings + subq_4.listing + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Aggregate Measures SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_3.listing + , SUM(subq_3.booking_value) AS booking_value FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['booking_value', 'listing'] SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'listing__views_times_booking_value'] + subq_2.listing + , subq_2.booking_value + 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_2 + ) subq_3 + GROUP BY + subq_3.listing + ) subq_4 + ) subq_5 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions SELECT - subq_14.listing - , subq_14.listing__views_times_booking_value + subq_8.listing + , subq_8.views FROM ( - -- Compute Metrics via Expressions + -- Aggregate Measures SELECT - subq_13.listing - , booking_value * views AS listing__views_times_booking_value + subq_7.listing + , SUM(subq_7.views) AS views FROM ( - -- Combine Aggregated Outputs + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['views', 'listing'] SELECT - COALESCE(subq_7.listing, subq_12.listing) AS listing - , MAX(subq_7.booking_value) AS booking_value - , MAX(subq_12.views) AS views + subq_6.listing + , subq_6.views FROM ( - -- Compute Metrics via Expressions - SELECT - subq_6.listing - , subq_6.booking_value - FROM ( - -- Aggregate Measures - SELECT - subq_5.listing - , SUM(subq_5.booking_value) AS booking_value - FROM ( - -- Pass Only Elements: ['booking_value', 'listing'] - SELECT - subq_4.listing - , subq_4.booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.paid_at__day - , subq_3.paid_at__week - , subq_3.paid_at__month - , subq_3.paid_at__quarter - , subq_3.paid_at__year - , subq_3.paid_at__extract_year - , subq_3.paid_at__extract_quarter - , subq_3.paid_at__extract_month - , subq_3.paid_at__extract_day - , subq_3.paid_at__extract_dow - , subq_3.paid_at__extract_doy - , subq_3.booking__ds__day - , subq_3.booking__ds__week - , subq_3.booking__ds__month - , subq_3.booking__ds__quarter - , subq_3.booking__ds__year - , subq_3.booking__ds__extract_year - , subq_3.booking__ds__extract_quarter - , subq_3.booking__ds__extract_month - , subq_3.booking__ds__extract_day - , subq_3.booking__ds__extract_dow - , subq_3.booking__ds__extract_doy - , subq_3.booking__ds_partitioned__day - , subq_3.booking__ds_partitioned__week - , subq_3.booking__ds_partitioned__month - , subq_3.booking__ds_partitioned__quarter - , subq_3.booking__ds_partitioned__year - , subq_3.booking__ds_partitioned__extract_year - , subq_3.booking__ds_partitioned__extract_quarter - , subq_3.booking__ds_partitioned__extract_month - , subq_3.booking__ds_partitioned__extract_day - , subq_3.booking__ds_partitioned__extract_dow - , subq_3.booking__ds_partitioned__extract_doy - , subq_3.booking__paid_at__day - , subq_3.booking__paid_at__week - , subq_3.booking__paid_at__month - , subq_3.booking__paid_at__quarter - , subq_3.booking__paid_at__year - , subq_3.booking__paid_at__extract_year - , subq_3.booking__paid_at__extract_quarter - , subq_3.booking__paid_at__extract_month - , subq_3.booking__paid_at__extract_day - , subq_3.booking__paid_at__extract_dow - , subq_3.booking__paid_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.guest - , subq_3.host - , subq_3.booking__listing - , subq_3.booking__guest - , subq_3.booking__host - , subq_3.is_instant - , subq_3.booking__is_instant - , subq_3.bookings - , subq_3.instant_bookings - , subq_3.booking_value - , subq_3.max_booking_value - , subq_3.min_booking_value - , subq_3.bookers - , subq_3.average_booking_value - , subq_3.referred_bookings - , subq_3.median_booking_value - , subq_3.booking_value_p99 - , subq_3.discrete_booking_value_p99 - , subq_3.approximate_continuous_booking_value_p99 - , subq_3.approximate_discrete_booking_value_p99 - 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_3 - ) subq_4 - ) subq_5 - GROUP BY - subq_5.listing - ) subq_6 - ) subq_7 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'views_source' SELECT - subq_11.listing - , subq_11.views - FROM ( - -- Aggregate Measures - SELECT - subq_10.listing - , SUM(subq_10.views) AS views - FROM ( - -- Pass Only Elements: ['views', 'listing'] - SELECT - subq_9.listing - , subq_9.views - 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.view__ds__day - , subq_8.view__ds__week - , subq_8.view__ds__month - , subq_8.view__ds__quarter - , subq_8.view__ds__year - , subq_8.view__ds__extract_year - , subq_8.view__ds__extract_quarter - , subq_8.view__ds__extract_month - , subq_8.view__ds__extract_day - , subq_8.view__ds__extract_dow - , subq_8.view__ds__extract_doy - , subq_8.view__ds_partitioned__day - , subq_8.view__ds_partitioned__week - , subq_8.view__ds_partitioned__month - , subq_8.view__ds_partitioned__quarter - , subq_8.view__ds_partitioned__year - , subq_8.view__ds_partitioned__extract_year - , subq_8.view__ds_partitioned__extract_quarter - , subq_8.view__ds_partitioned__extract_month - , subq_8.view__ds_partitioned__extract_day - , subq_8.view__ds_partitioned__extract_dow - , subq_8.view__ds_partitioned__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.user - , subq_8.view__listing - , subq_8.view__user - , subq_8.views - FROM ( - -- Read Elements From Semantic Model 'views_source' - SELECT - 1 AS views - , DATE_TRUNC('day', views_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', views_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', views_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', views_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', views_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM views_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM views_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds) AS view__ds__day - , DATE_TRUNC('week', views_source_src_28000.ds) AS view__ds__week - , DATE_TRUNC('month', views_source_src_28000.ds) AS view__ds__month - , DATE_TRUNC('quarter', views_source_src_28000.ds) AS view__ds__quarter - , DATE_TRUNC('year', views_source_src_28000.ds) AS view__ds__year - , EXTRACT(year FROM views_source_src_28000.ds) AS view__ds__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds) AS view__ds__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds) AS view__ds__extract_month - , EXTRACT(day FROM views_source_src_28000.ds) AS view__ds__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds) AS view__ds__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds) AS view__ds__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__day - , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__week - , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__year - , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_doy - , views_source_src_28000.listing_id AS listing - , views_source_src_28000.user_id AS user - , views_source_src_28000.listing_id AS view__listing - , views_source_src_28000.user_id AS view__user - FROM ***************************.fct_views views_source_src_28000 - ) subq_8 - ) subq_9 - ) subq_10 - GROUP BY - subq_10.listing - ) subq_11 - ) subq_12 - ON - subq_7.listing = subq_12.listing - GROUP BY - COALESCE(subq_7.listing, subq_12.listing) - ) subq_13 - ) subq_14 - ) subq_15 + 1 AS views + , DATE_TRUNC('day', views_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', views_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', views_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', views_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', views_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM views_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM views_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds) AS view__ds__day + , DATE_TRUNC('week', views_source_src_28000.ds) AS view__ds__week + , DATE_TRUNC('month', views_source_src_28000.ds) AS view__ds__month + , DATE_TRUNC('quarter', views_source_src_28000.ds) AS view__ds__quarter + , DATE_TRUNC('year', views_source_src_28000.ds) AS view__ds__year + , EXTRACT(year FROM views_source_src_28000.ds) AS view__ds__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds) AS view__ds__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds) AS view__ds__extract_month + , EXTRACT(day FROM views_source_src_28000.ds) AS view__ds__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds) AS view__ds__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds) AS view__ds__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__day + , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__week + , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__year + , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_doy + , views_source_src_28000.listing_id AS listing + , views_source_src_28000.user_id AS user + , views_source_src_28000.listing_id AS view__listing + , views_source_src_28000.user_id AS view__user + FROM ***************************.fct_views views_source_src_28000 + ) subq_6 + ) subq_7 + GROUP BY + subq_7.listing + ) subq_8 + ) subq_9 ON - subq_2.listing = subq_15.listing - ) subq_16 - ) subq_17 - WHERE listing__views_times_booking_value > 1 - ) subq_18 - ) subq_19 -) subq_20 + subq_5.listing = subq_9.listing + GROUP BY + COALESCE(subq_5.listing, subq_9.listing) + ) subq_10 + ) subq_11 + ON + subq_1.listing = subq_11.listing + ) subq_12 + WHERE listing__views_times_booking_value > 1 + ) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0_optimized.sql index e5f6bf61fb..5e02f589ed 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_derived_metric_in_where_filter__plan0_optimized.sql @@ -8,8 +8,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['listings', 'listing__views_times_booking_value'] SELECT - subq_36.listing__views_times_booking_value AS listing__views_times_booking_value - , subq_23.listings AS listings + subq_26.listing__views_times_booking_value AS listing__views_times_booking_value + , subq_16.listings AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -18,7 +18,7 @@ FROM ( listing_id AS listing , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_23 + ) subq_16 LEFT OUTER JOIN ( -- Compute Metrics via Expressions -- Pass Only Elements: ['listing', 'listing__views_times_booking_value'] @@ -28,9 +28,9 @@ FROM ( FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_28.listing, subq_33.listing) AS listing - , MAX(subq_28.booking_value) AS booking_value - , MAX(subq_33.views) AS views + COALESCE(subq_20.listing, subq_24.listing) AS listing + , MAX(subq_20.booking_value) AS booking_value + , MAX(subq_24.views) AS views FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -43,7 +43,7 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY listing_id - ) subq_28 + ) subq_20 FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -58,17 +58,17 @@ FROM ( listing_id AS listing , 1 AS views FROM ***************************.fct_views views_source_src_28000 - ) subq_31 + ) subq_22 GROUP BY listing - ) subq_33 + ) subq_24 ON - subq_28.listing = subq_33.listing + subq_20.listing = subq_24.listing GROUP BY - COALESCE(subq_28.listing, subq_33.listing) - ) subq_34 - ) subq_36 + COALESCE(subq_20.listing, subq_24.listing) + ) subq_25 + ) subq_26 ON - subq_23.listing = subq_36.listing -) subq_38 + subq_16.listing = subq_26.listing +) subq_27 WHERE listing__views_times_booking_value > 1 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0.sql index 076b390821..6e8d92c09a 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0.sql @@ -1,620 +1,325 @@ -- Compute Metrics via Expressions SELECT - subq_19.listings + subq_12.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_18.listings) AS listings + SUM(subq_11.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings',] SELECT - subq_17.listings + subq_10.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'listing__bookings', 'listing__bookers'] SELECT - subq_16.listing__bookings - , subq_16.listing__bookers - , subq_16.listings + subq_5.listing__bookings AS listing__bookings + , subq_9.listing__bookers AS listing__bookers + , subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'listing__bookings', 'listing__bookers'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'listing', 'listing'] SELECT - subq_15.listing__bookings - , subq_15.listing__bookers - , subq_15.listings + subq_0.listing + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.listing AS listing - , subq_8.listing__bookings AS listing__bookings - , subq_14.listing__bookers AS listing__bookers - , subq_2.listings AS listings + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing', 'listing__bookings'] + SELECT + subq_4.listing + , subq_4.bookings AS listing__bookings + FROM ( + -- Aggregate Measures + SELECT + subq_3.listing + , SUM(subq_3.bookings) AS bookings FROM ( - -- Pass Only Elements: ['listings', 'listing', 'listing'] - SELECT - subq_1.listing - , subq_1.listings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'listing__bookings'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'listing'] SELECT - subq_7.listing - , subq_7.listing__bookings + subq_2.listing + , subq_2.bookings FROM ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_6.listing - , subq_6.bookings AS listing__bookings - FROM ( - -- Aggregate Measures - SELECT - subq_5.listing - , SUM(subq_5.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'listing'] - SELECT - subq_4.listing - , subq_4.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.paid_at__day - , subq_3.paid_at__week - , subq_3.paid_at__month - , subq_3.paid_at__quarter - , subq_3.paid_at__year - , subq_3.paid_at__extract_year - , subq_3.paid_at__extract_quarter - , subq_3.paid_at__extract_month - , subq_3.paid_at__extract_day - , subq_3.paid_at__extract_dow - , subq_3.paid_at__extract_doy - , subq_3.booking__ds__day - , subq_3.booking__ds__week - , subq_3.booking__ds__month - , subq_3.booking__ds__quarter - , subq_3.booking__ds__year - , subq_3.booking__ds__extract_year - , subq_3.booking__ds__extract_quarter - , subq_3.booking__ds__extract_month - , subq_3.booking__ds__extract_day - , subq_3.booking__ds__extract_dow - , subq_3.booking__ds__extract_doy - , subq_3.booking__ds_partitioned__day - , subq_3.booking__ds_partitioned__week - , subq_3.booking__ds_partitioned__month - , subq_3.booking__ds_partitioned__quarter - , subq_3.booking__ds_partitioned__year - , subq_3.booking__ds_partitioned__extract_year - , subq_3.booking__ds_partitioned__extract_quarter - , subq_3.booking__ds_partitioned__extract_month - , subq_3.booking__ds_partitioned__extract_day - , subq_3.booking__ds_partitioned__extract_dow - , subq_3.booking__ds_partitioned__extract_doy - , subq_3.booking__paid_at__day - , subq_3.booking__paid_at__week - , subq_3.booking__paid_at__month - , subq_3.booking__paid_at__quarter - , subq_3.booking__paid_at__year - , subq_3.booking__paid_at__extract_year - , subq_3.booking__paid_at__extract_quarter - , subq_3.booking__paid_at__extract_month - , subq_3.booking__paid_at__extract_day - , subq_3.booking__paid_at__extract_dow - , subq_3.booking__paid_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.guest - , subq_3.host - , subq_3.booking__listing - , subq_3.booking__guest - , subq_3.booking__host - , subq_3.is_instant - , subq_3.booking__is_instant - , subq_3.bookings - , subq_3.instant_bookings - , subq_3.booking_value - , subq_3.max_booking_value - , subq_3.min_booking_value - , subq_3.bookers - , subq_3.average_booking_value - , subq_3.referred_bookings - , subq_3.median_booking_value - , subq_3.booking_value_p99 - , subq_3.discrete_booking_value_p99 - , subq_3.approximate_continuous_booking_value_p99 - , subq_3.approximate_discrete_booking_value_p99 - 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_3 - ) subq_4 - ) subq_5 - GROUP BY - subq_5.listing - ) subq_6 - ) subq_7 - ) subq_8 - ON - subq_2.listing = subq_8.listing - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'listing__bookers'] + 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_2 + ) subq_3 + GROUP BY + subq_3.listing + ) subq_4 + ) subq_5 + ON + subq_1.listing = subq_5.listing + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing', 'listing__bookers'] + SELECT + subq_8.listing + , subq_8.bookers AS listing__bookers + FROM ( + -- Aggregate Measures + SELECT + subq_7.listing + , COUNT(DISTINCT subq_7.bookers) AS bookers + FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'listing'] SELECT - subq_13.listing - , subq_13.listing__bookers + subq_6.listing + , subq_6.bookers FROM ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_12.listing - , subq_12.bookers AS listing__bookers - FROM ( - -- Aggregate Measures - SELECT - subq_11.listing - , COUNT(DISTINCT subq_11.bookers) AS bookers - FROM ( - -- Pass Only Elements: ['bookers', 'listing'] - SELECT - subq_10.listing - , subq_10.bookers - 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 - 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_9 - ) subq_10 - ) subq_11 - GROUP BY - subq_11.listing - ) subq_12 - ) subq_13 - ) subq_14 - ON - subq_2.listing = subq_14.listing - ) subq_15 - ) subq_16 - WHERE listing__bookings > 2 AND listing__bookers > 1 - ) subq_17 - ) subq_18 -) subq_19 + 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_6 + ) subq_7 + GROUP BY + subq_7.listing + ) subq_8 + ) subq_9 + ON + subq_1.listing = subq_9.listing + ) subq_10 + WHERE listing__bookings > 2 AND listing__bookers > 1 + ) subq_11 +) subq_12 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0_optimized.sql index 767f0b3fea..4c94abf8eb 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_multiple_metrics_in_filter__plan0_optimized.sql @@ -8,9 +8,9 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['listings', 'listing__bookings', 'listing__bookers'] SELECT - subq_28.listing__bookings AS listing__bookings - , subq_34.listing__bookers AS listing__bookers - , subq_22.listings AS listings + subq_18.listing__bookings AS listing__bookings + , subq_22.listing__bookers AS listing__bookers + , subq_14.listings AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -19,7 +19,7 @@ FROM ( listing_id AS listing , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_22 + ) subq_14 LEFT OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -35,12 +35,12 @@ FROM ( listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_25 + ) subq_16 GROUP BY listing - ) subq_28 + ) subq_18 ON - subq_22.listing = subq_28.listing + subq_14.listing = subq_18.listing LEFT OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -54,8 +54,8 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY listing_id - ) subq_34 + ) subq_22 ON - subq_22.listing = subq_34.listing -) subq_36 + subq_14.listing = subq_22.listing +) subq_23 WHERE listing__bookings > 2 AND listing__bookers > 1 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0.sql index 6d407fb8ca..993057d452 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0.sql @@ -1,626 +1,338 @@ -- Compute Metrics via Expressions SELECT - subq_20.listings + subq_14.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_19.listings) AS listings + SUM(subq_13.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings',] SELECT - subq_18.listings + subq_12.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'listing__bookings_per_booker'] SELECT - subq_17.listing__bookings_per_booker - , subq_17.listings + subq_11.listing__bookings_per_booker AS listing__bookings_per_booker + , subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'listing__bookings_per_booker'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'listing'] SELECT - subq_16.listing__bookings_per_booker - , subq_16.listings + subq_0.listing + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.listing AS listing - , subq_15.listing__bookings_per_booker AS listing__bookings_per_booker - , subq_2.listings AS listings + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing', 'listing__bookings_per_booker'] + SELECT + subq_10.listing + , CAST(subq_10.bookings AS DOUBLE) / CAST(NULLIF(subq_10.bookers, 0) AS DOUBLE) AS listing__bookings_per_booker + FROM ( + -- Combine Aggregated Outputs + SELECT + COALESCE(subq_5.listing, subq_9.listing) AS listing + , MAX(subq_5.bookings) AS bookings + , MAX(subq_9.bookers) AS bookers FROM ( - -- Pass Only Elements: ['listings', 'listing'] + -- Compute Metrics via Expressions SELECT - subq_1.listing - , subq_1.listings + subq_4.listing + , subq_4.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Aggregate Measures SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing + subq_3.listing + , SUM(subq_3.bookings) AS bookings FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'listing'] SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'listing__bookings_per_booker'] + subq_2.listing + , subq_2.bookings + 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_2 + ) subq_3 + GROUP BY + subq_3.listing + ) subq_4 + ) subq_5 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions SELECT - subq_14.listing - , subq_14.listing__bookings_per_booker + subq_8.listing + , subq_8.bookers FROM ( - -- Compute Metrics via Expressions + -- Aggregate Measures SELECT - subq_13.listing - , CAST(subq_13.bookings AS DOUBLE) / CAST(NULLIF(subq_13.bookers, 0) AS DOUBLE) AS listing__bookings_per_booker + subq_7.listing + , COUNT(DISTINCT subq_7.bookers) AS bookers FROM ( - -- Combine Aggregated Outputs + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookers', 'listing'] SELECT - COALESCE(subq_7.listing, subq_12.listing) AS listing - , MAX(subq_7.bookings) AS bookings - , MAX(subq_12.bookers) AS bookers + subq_6.listing + , subq_6.bookers FROM ( - -- Compute Metrics via Expressions - SELECT - subq_6.listing - , subq_6.bookings - FROM ( - -- Aggregate Measures - SELECT - subq_5.listing - , SUM(subq_5.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'listing'] - SELECT - subq_4.listing - , subq_4.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.paid_at__day - , subq_3.paid_at__week - , subq_3.paid_at__month - , subq_3.paid_at__quarter - , subq_3.paid_at__year - , subq_3.paid_at__extract_year - , subq_3.paid_at__extract_quarter - , subq_3.paid_at__extract_month - , subq_3.paid_at__extract_day - , subq_3.paid_at__extract_dow - , subq_3.paid_at__extract_doy - , subq_3.booking__ds__day - , subq_3.booking__ds__week - , subq_3.booking__ds__month - , subq_3.booking__ds__quarter - , subq_3.booking__ds__year - , subq_3.booking__ds__extract_year - , subq_3.booking__ds__extract_quarter - , subq_3.booking__ds__extract_month - , subq_3.booking__ds__extract_day - , subq_3.booking__ds__extract_dow - , subq_3.booking__ds__extract_doy - , subq_3.booking__ds_partitioned__day - , subq_3.booking__ds_partitioned__week - , subq_3.booking__ds_partitioned__month - , subq_3.booking__ds_partitioned__quarter - , subq_3.booking__ds_partitioned__year - , subq_3.booking__ds_partitioned__extract_year - , subq_3.booking__ds_partitioned__extract_quarter - , subq_3.booking__ds_partitioned__extract_month - , subq_3.booking__ds_partitioned__extract_day - , subq_3.booking__ds_partitioned__extract_dow - , subq_3.booking__ds_partitioned__extract_doy - , subq_3.booking__paid_at__day - , subq_3.booking__paid_at__week - , subq_3.booking__paid_at__month - , subq_3.booking__paid_at__quarter - , subq_3.booking__paid_at__year - , subq_3.booking__paid_at__extract_year - , subq_3.booking__paid_at__extract_quarter - , subq_3.booking__paid_at__extract_month - , subq_3.booking__paid_at__extract_day - , subq_3.booking__paid_at__extract_dow - , subq_3.booking__paid_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.guest - , subq_3.host - , subq_3.booking__listing - , subq_3.booking__guest - , subq_3.booking__host - , subq_3.is_instant - , subq_3.booking__is_instant - , subq_3.bookings - , subq_3.instant_bookings - , subq_3.booking_value - , subq_3.max_booking_value - , subq_3.min_booking_value - , subq_3.bookers - , subq_3.average_booking_value - , subq_3.referred_bookings - , subq_3.median_booking_value - , subq_3.booking_value_p99 - , subq_3.discrete_booking_value_p99 - , subq_3.approximate_continuous_booking_value_p99 - , subq_3.approximate_discrete_booking_value_p99 - 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_3 - ) subq_4 - ) subq_5 - GROUP BY - subq_5.listing - ) subq_6 - ) subq_7 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_11.listing - , subq_11.bookers - FROM ( - -- Aggregate Measures - SELECT - subq_10.listing - , COUNT(DISTINCT subq_10.bookers) AS bookers - FROM ( - -- Pass Only Elements: ['bookers', 'listing'] - SELECT - subq_9.listing - , subq_9.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 - 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_8 - ) subq_9 - ) subq_10 - GROUP BY - subq_10.listing - ) subq_11 - ) subq_12 - ON - subq_7.listing = subq_12.listing - GROUP BY - COALESCE(subq_7.listing, subq_12.listing) - ) subq_13 - ) subq_14 - ) subq_15 + 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_6 + ) subq_7 + GROUP BY + subq_7.listing + ) subq_8 + ) subq_9 ON - subq_2.listing = subq_15.listing - ) subq_16 - ) subq_17 - WHERE listing__bookings_per_booker > 1 - ) subq_18 - ) subq_19 -) subq_20 + subq_5.listing = subq_9.listing + GROUP BY + COALESCE(subq_5.listing, subq_9.listing) + ) subq_10 + ) subq_11 + ON + subq_1.listing = subq_11.listing + ) subq_12 + WHERE listing__bookings_per_booker > 1 + ) subq_13 +) subq_14 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0_optimized.sql index 4847f003cd..3075803e73 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_ratio_metric_in_where_filter__plan0_optimized.sql @@ -8,8 +8,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['listings', 'listing__bookings_per_booker'] SELECT - CAST(subq_28.bookings AS DOUBLE) / CAST(NULLIF(subq_28.bookers, 0) AS DOUBLE) AS listing__bookings_per_booker - , subq_23.listings AS listings + CAST(subq_20.bookings AS DOUBLE) / CAST(NULLIF(subq_20.bookers, 0) AS DOUBLE) AS listing__bookings_per_booker + , subq_16.listings AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -18,7 +18,7 @@ FROM ( listing_id AS listing , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_23 + ) subq_16 LEFT OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -35,11 +35,11 @@ FROM ( , 1 AS bookings , guest_id AS bookers FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_26 + ) subq_18 GROUP BY listing - ) subq_28 + ) subq_20 ON - subq_23.listing = subq_28.listing -) subq_32 + subq_16.listing = subq_20.listing +) subq_22 WHERE listing__bookings_per_booker > 1 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0.sql index d42f3e3875..2508625236 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0.sql @@ -1,394 +1,207 @@ -- Compute Metrics via Expressions SELECT - subq_13.listings + subq_8.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_12.listings) AS listings + SUM(subq_7.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings',] SELECT - subq_11.listings + subq_6.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'listing__bookings'] SELECT - subq_10.listing__bookings - , subq_10.listings + subq_5.listing__bookings AS listing__bookings + , subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'listing__bookings'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'listing'] SELECT - subq_9.listing__bookings - , subq_9.listings + subq_0.listing + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.listing AS listing - , subq_8.listing__bookings AS listing__bookings - , subq_2.listings AS listings + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Compute Metrics via Expressions + -- Pass Only Elements: ['listing', 'listing__bookings'] + SELECT + subq_4.listing + , subq_4.bookings AS listing__bookings + FROM ( + -- Aggregate Measures + SELECT + subq_3.listing + , SUM(subq_3.bookings) AS bookings FROM ( - -- Pass Only Elements: ['listings', 'listing'] - SELECT - subq_1.listing - , subq_1.listings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['listing', 'listing__bookings'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'listing'] SELECT - subq_7.listing - , subq_7.listing__bookings + subq_2.listing + , subq_2.bookings FROM ( - -- Compute Metrics via Expressions + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_6.listing - , subq_6.bookings AS listing__bookings - FROM ( - -- Aggregate Measures - SELECT - subq_5.listing - , SUM(subq_5.bookings) AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'listing'] - SELECT - subq_4.listing - , subq_4.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.paid_at__day - , subq_3.paid_at__week - , subq_3.paid_at__month - , subq_3.paid_at__quarter - , subq_3.paid_at__year - , subq_3.paid_at__extract_year - , subq_3.paid_at__extract_quarter - , subq_3.paid_at__extract_month - , subq_3.paid_at__extract_day - , subq_3.paid_at__extract_dow - , subq_3.paid_at__extract_doy - , subq_3.booking__ds__day - , subq_3.booking__ds__week - , subq_3.booking__ds__month - , subq_3.booking__ds__quarter - , subq_3.booking__ds__year - , subq_3.booking__ds__extract_year - , subq_3.booking__ds__extract_quarter - , subq_3.booking__ds__extract_month - , subq_3.booking__ds__extract_day - , subq_3.booking__ds__extract_dow - , subq_3.booking__ds__extract_doy - , subq_3.booking__ds_partitioned__day - , subq_3.booking__ds_partitioned__week - , subq_3.booking__ds_partitioned__month - , subq_3.booking__ds_partitioned__quarter - , subq_3.booking__ds_partitioned__year - , subq_3.booking__ds_partitioned__extract_year - , subq_3.booking__ds_partitioned__extract_quarter - , subq_3.booking__ds_partitioned__extract_month - , subq_3.booking__ds_partitioned__extract_day - , subq_3.booking__ds_partitioned__extract_dow - , subq_3.booking__ds_partitioned__extract_doy - , subq_3.booking__paid_at__day - , subq_3.booking__paid_at__week - , subq_3.booking__paid_at__month - , subq_3.booking__paid_at__quarter - , subq_3.booking__paid_at__year - , subq_3.booking__paid_at__extract_year - , subq_3.booking__paid_at__extract_quarter - , subq_3.booking__paid_at__extract_month - , subq_3.booking__paid_at__extract_day - , subq_3.booking__paid_at__extract_dow - , subq_3.booking__paid_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.guest - , subq_3.host - , subq_3.booking__listing - , subq_3.booking__guest - , subq_3.booking__host - , subq_3.is_instant - , subq_3.booking__is_instant - , subq_3.bookings - , subq_3.instant_bookings - , subq_3.booking_value - , subq_3.max_booking_value - , subq_3.min_booking_value - , subq_3.bookers - , subq_3.average_booking_value - , subq_3.referred_bookings - , subq_3.median_booking_value - , subq_3.booking_value_p99 - , subq_3.discrete_booking_value_p99 - , subq_3.approximate_continuous_booking_value_p99 - , subq_3.approximate_discrete_booking_value_p99 - 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_3 - ) subq_4 - ) subq_5 - GROUP BY - subq_5.listing - ) subq_6 - ) subq_7 - ) subq_8 - ON - subq_2.listing = subq_8.listing - ) subq_9 - ) subq_10 - WHERE listing__bookings > 2 - ) subq_11 - ) subq_12 -) subq_13 + 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_2 + ) subq_3 + GROUP BY + subq_3.listing + ) subq_4 + ) subq_5 + ON + subq_1.listing = subq_5.listing + ) subq_6 + WHERE listing__bookings > 2 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0_optimized.sql index 48fed36d03..2e329d7b83 100644 --- a/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_filter_rendering.py/SqlQueryPlan/DuckDB/test_query_with_simple_metric_in_where_filter__plan0_optimized.sql @@ -8,8 +8,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['listings', 'listing__bookings'] SELECT - subq_22.listing__bookings AS listing__bookings - , subq_16.listings AS listings + subq_14.listing__bookings AS listing__bookings + , subq_10.listings AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -18,7 +18,7 @@ FROM ( listing_id AS listing , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_16 + ) subq_10 LEFT OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -34,11 +34,11 @@ FROM ( listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_19 + ) subq_12 GROUP BY listing - ) subq_22 + ) subq_14 ON - subq_16.listing = subq_22.listing -) subq_24 + subq_10.listing = subq_14.listing +) subq_15 WHERE listing__bookings > 2 diff --git a/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/DuckDB/test_simple_query_with_metric_time_dimension__plan0.sql b/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/DuckDB/test_simple_query_with_metric_time_dimension__plan0.sql index 67af06d832..da8572619d 100644 --- a/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/DuckDB/test_simple_query_with_metric_time_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/DuckDB/test_simple_query_with_metric_time_dimension__plan0.sql @@ -1,427 +1,237 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day - , MAX(subq_4.bookings) AS bookings - , MAX(subq_9.booking_payments) AS booking_payments + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) AS metric_time__day + , MAX(subq_3.bookings) AS bookings + , MAX(subq_7.booking_payments) AS booking_payments FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_2.metric_time__day + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 -) subq_4 + subq_1.metric_time__day + ) subq_2 +) subq_3 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking_payments + subq_6.metric_time__day + , subq_6.booking_payments FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.booking_payments) AS booking_payments + subq_5.metric_time__day + , SUM(subq_5.booking_payments) AS booking_payments FROM ( + -- Metric Time Dimension 'paid_at' -- Pass Only Elements: ['booking_payments', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.booking_payments + subq_4.paid_at__day AS metric_time__day + , subq_4.booking_payments FROM ( - -- Metric Time Dimension 'paid_at' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.paid_at__day AS metric_time__day - , subq_5.paid_at__week AS metric_time__week - , subq_5.paid_at__month AS metric_time__month - , subq_5.paid_at__quarter AS metric_time__quarter - , subq_5.paid_at__year AS metric_time__year - , subq_5.paid_at__extract_year AS metric_time__extract_year - , subq_5.paid_at__extract_quarter AS metric_time__extract_quarter - , subq_5.paid_at__extract_month AS metric_time__extract_month - , subq_5.paid_at__extract_day AS metric_time__extract_day - , subq_5.paid_at__extract_dow AS metric_time__extract_dow - , subq_5.paid_at__extract_doy AS 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.booking_payments - 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_5 - ) subq_6 - ) subq_7 + 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_4 + ) subq_5 GROUP BY - subq_7.metric_time__day - ) subq_8 -) subq_9 + subq_5.metric_time__day + ) subq_6 +) subq_7 ON - subq_4.metric_time__day = subq_9.metric_time__day + subq_3.metric_time__day = subq_7.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) diff --git a/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/DuckDB/test_simple_query_with_metric_time_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/DuckDB/test_simple_query_with_metric_time_dimension__plan0_optimized.sql index a308d09d3b..0b030e06b6 100644 --- a/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/DuckDB/test_simple_query_with_metric_time_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/DuckDB/test_simple_query_with_metric_time_dimension__plan0_optimized.sql @@ -1,8 +1,8 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_14.metric_time__day, subq_19.metric_time__day) AS metric_time__day - , MAX(subq_14.bookings) AS bookings - , MAX(subq_19.booking_payments) AS booking_payments + COALESCE(subq_11.metric_time__day, subq_15.metric_time__day) AS metric_time__day + , MAX(subq_11.bookings) AS bookings + , MAX(subq_15.booking_payments) AS booking_payments FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -17,10 +17,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_12 + ) subq_9 GROUP BY metric_time__day -) subq_14 +) subq_11 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'paid_at' @@ -33,8 +33,8 @@ FULL OUTER JOIN ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', paid_at) -) subq_19 +) subq_15 ON - subq_14.metric_time__day = subq_19.metric_time__day + subq_11.metric_time__day = subq_15.metric_time__day GROUP BY - COALESCE(subq_14.metric_time__day, subq_19.metric_time__day) + COALESCE(subq_11.metric_time__day, subq_15.metric_time__day) diff --git a/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/test_simple_query_with_metric_time_dimension__plan0.xml b/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/test_simple_query_with_metric_time_dimension__plan0.xml index cbbc25a9f4..dfdee3df34 100644 --- a/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/test_simple_query_with_metric_time_dimension__plan0.xml +++ b/tests_metricflow/snapshots/test_metric_time_dimension_to_sql.py/SqlQueryPlan/test_simple_query_with_metric_time_dimension__plan0.xml @@ -21,7 +21,7 @@ - + @@ -36,951 +36,467 @@ - - + + - - + + - - + + - + + - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + @@ -989,9 +505,9 @@ - + - + @@ -999,7 +515,7 @@ - + @@ -1007,886 +523,453 @@ - + - + + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_dimensions_with_time_constraint__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_dimensions_with_time_constraint__plan0.sql index 924b094be0..37419224be 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_dimensions_with_time_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_dimensions_with_time_constraint__plan0.sql @@ -1,283 +1,167 @@ +-- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.listing__is_lux_latest - , subq_7.user__home_state_latest + subq_4.metric_time__day + , subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest FROM ( - -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-03T00:00:00] + -- Join Standard Outputs SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.created_at__day - , subq_6.created_at__week - , subq_6.created_at__month - , subq_6.created_at__quarter - , subq_6.created_at__year - , subq_6.created_at__extract_year - , subq_6.created_at__extract_quarter - , subq_6.created_at__extract_month - , subq_6.created_at__extract_day - , subq_6.created_at__extract_dow - , subq_6.created_at__extract_doy - , subq_6.listing__ds__day - , subq_6.listing__ds__week - , subq_6.listing__ds__month - , subq_6.listing__ds__quarter - , subq_6.listing__ds__year - , subq_6.listing__ds__extract_year - , subq_6.listing__ds__extract_quarter - , subq_6.listing__ds__extract_month - , subq_6.listing__ds__extract_day - , subq_6.listing__ds__extract_dow - , subq_6.listing__ds__extract_doy - , subq_6.listing__created_at__day - , subq_6.listing__created_at__week - , subq_6.listing__created_at__month - , subq_6.listing__created_at__quarter - , subq_6.listing__created_at__year - , subq_6.listing__created_at__extract_year - , subq_6.listing__created_at__extract_quarter - , subq_6.listing__created_at__extract_month - , subq_6.listing__created_at__extract_day - , subq_6.listing__created_at__extract_dow - , subq_6.listing__created_at__extract_doy - , subq_6.metric_time__day - , subq_6.listing - , subq_6.user - , subq_6.listing__user - , subq_6.country_latest - , subq_6.is_lux_latest - , subq_6.capacity_latest - , subq_6.listing__country_latest - , subq_6.listing__is_lux_latest - , subq_6.listing__capacity_latest - , subq_6.user__home_state_latest - , subq_6.listings - , subq_6.largest_listing - , subq_6.smallest_listing + 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.created_at__day AS created_at__day + , subq_0.created_at__week AS created_at__week + , subq_0.created_at__month AS created_at__month + , subq_0.created_at__quarter AS created_at__quarter + , subq_0.created_at__year AS created_at__year + , subq_0.created_at__extract_year AS created_at__extract_year + , subq_0.created_at__extract_quarter AS created_at__extract_quarter + , subq_0.created_at__extract_month AS created_at__extract_month + , subq_0.created_at__extract_day AS created_at__extract_day + , subq_0.created_at__extract_dow AS created_at__extract_dow + , subq_0.created_at__extract_doy AS created_at__extract_doy + , subq_0.listing__ds__day AS listing__ds__day + , subq_0.listing__ds__week AS listing__ds__week + , subq_0.listing__ds__month AS listing__ds__month + , subq_0.listing__ds__quarter AS listing__ds__quarter + , subq_0.listing__ds__year AS listing__ds__year + , subq_0.listing__ds__extract_year AS listing__ds__extract_year + , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter + , subq_0.listing__ds__extract_month AS listing__ds__extract_month + , subq_0.listing__ds__extract_day AS listing__ds__extract_day + , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow + , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy + , subq_0.listing__created_at__day AS listing__created_at__day + , subq_0.listing__created_at__week AS listing__created_at__week + , subq_0.listing__created_at__month AS listing__created_at__month + , subq_0.listing__created_at__quarter AS listing__created_at__quarter + , subq_0.listing__created_at__year AS listing__created_at__year + , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year + , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter + , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month + , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day + , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow + , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy + , subq_2.metric_time__day AS metric_time__day + , subq_0.listing AS listing + , subq_0.user AS user + , subq_0.listing__user AS listing__user + , subq_0.country_latest AS country_latest + , subq_0.is_lux_latest AS is_lux_latest + , subq_0.capacity_latest AS capacity_latest + , subq_0.listing__country_latest AS listing__country_latest + , subq_0.listing__is_lux_latest AS listing__is_lux_latest + , subq_0.listing__capacity_latest AS listing__capacity_latest + , subq_3.home_state_latest AS user__home_state_latest + , subq_0.listings AS listings + , subq_0.largest_listing AS largest_listing + , subq_0.smallest_listing AS smallest_listing FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' 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.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_3.metric_time__day AS metric_time__day - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_5.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + CROSS JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_1.ds__day AS metric_time__day FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - CROSS JOIN ( - -- Pass Only Elements: ['metric_time__day',] + -- Time Spine SELECT - subq_2.metric_time__day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.ds__martian_day - , subq_1.ds__day AS metric_time__day - , subq_1.ds__week AS metric_time__week - , subq_1.ds__month AS metric_time__month - , subq_1.ds__quarter AS metric_time__quarter - , subq_1.ds__year AS metric_time__year - , subq_1.ds__extract_year AS metric_time__extract_year - , subq_1.ds__extract_quarter AS metric_time__extract_quarter - , subq_1.ds__extract_month AS metric_time__extract_month - , subq_1.ds__extract_day AS metric_time__extract_day - , subq_1.ds__extract_dow AS metric_time__extract_dow - , subq_1.ds__extract_doy AS metric_time__extract_doy - , subq_1.ds__martian_day AS metric_time__martian_day - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day - , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week - , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month - , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter - , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year - , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year - , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter - , EXTRACT(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_1 - ) subq_2 - ) subq_3 - FULL OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_4.user - , subq_4.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_4 - ) subq_5 - ON - subq_0.user = subq_5.user - ) subq_6 - WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' -) subq_7 + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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_1 + ) subq_2 + FULL OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_3 + ON + subq_0.user = subq_3.user +) subq_4 +WHERE subq_4.metric_time__day BETWEEN '2020-01-01' AND '2020-01-03' GROUP BY - subq_7.metric_time__day - , subq_7.listing__is_lux_latest - , subq_7.user__home_state_latest + subq_4.metric_time__day + , subq_4.listing__is_lux_latest + , subq_4.user__home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_only__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_only__plan0.sql index d0ef8e46cd..1a71bdfbe5 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_only__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_only__plan0.sql @@ -1,50 +1,23 @@ +-- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - subq_1.metric_time__day + subq_0.ds__day AS metric_time__day FROM ( - -- Metric Time Dimension 'ds' + -- Time Spine SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds__martian_day - , 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.ds__martian_day AS metric_time__martian_day - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day - , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week - , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month - , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter - , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year - , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year - , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter - , EXTRACT(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_0 -) subq_1 + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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_0 GROUP BY - subq_1.metric_time__day + subq_0.ds__day diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_quarter_alone__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_quarter_alone__plan0.sql index 7f6e052f78..f75a4630b9 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_quarter_alone__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_quarter_alone__plan0.sql @@ -1,50 +1,23 @@ +-- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__quarter',] SELECT - subq_1.metric_time__quarter + subq_0.ds__quarter AS metric_time__quarter FROM ( - -- Metric Time Dimension 'ds' + -- Time Spine SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds__martian_day - , 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.ds__martian_day AS metric_time__martian_day - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day - , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week - , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month - , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter - , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year - , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year - , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter - , EXTRACT(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_0 -) subq_1 + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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_0 GROUP BY - subq_1.metric_time__quarter + subq_0.ds__quarter diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_with_other_dimensions__plan0.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_with_other_dimensions__plan0.sql index 9997adfc98..5bc3c4a746 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_with_other_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_with_other_dimensions__plan0.sql @@ -1,220 +1,102 @@ +-- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.listing__is_lux_latest - , subq_6.user__home_state_latest + subq_2.metric_time__day AS metric_time__day + , subq_0.listing__is_lux_latest AS listing__is_lux_latest FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' 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.created_at__day AS created_at__day - , subq_0.created_at__week AS created_at__week - , subq_0.created_at__month AS created_at__month - , subq_0.created_at__quarter AS created_at__quarter - , subq_0.created_at__year AS created_at__year - , subq_0.created_at__extract_year AS created_at__extract_year - , subq_0.created_at__extract_quarter AS created_at__extract_quarter - , subq_0.created_at__extract_month AS created_at__extract_month - , subq_0.created_at__extract_day AS created_at__extract_day - , subq_0.created_at__extract_dow AS created_at__extract_dow - , subq_0.created_at__extract_doy AS created_at__extract_doy - , subq_0.listing__ds__day AS listing__ds__day - , subq_0.listing__ds__week AS listing__ds__week - , subq_0.listing__ds__month AS listing__ds__month - , subq_0.listing__ds__quarter AS listing__ds__quarter - , subq_0.listing__ds__year AS listing__ds__year - , subq_0.listing__ds__extract_year AS listing__ds__extract_year - , subq_0.listing__ds__extract_quarter AS listing__ds__extract_quarter - , subq_0.listing__ds__extract_month AS listing__ds__extract_month - , subq_0.listing__ds__extract_day AS listing__ds__extract_day - , subq_0.listing__ds__extract_dow AS listing__ds__extract_dow - , subq_0.listing__ds__extract_doy AS listing__ds__extract_doy - , subq_0.listing__created_at__day AS listing__created_at__day - , subq_0.listing__created_at__week AS listing__created_at__week - , subq_0.listing__created_at__month AS listing__created_at__month - , subq_0.listing__created_at__quarter AS listing__created_at__quarter - , subq_0.listing__created_at__year AS listing__created_at__year - , subq_0.listing__created_at__extract_year AS listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter AS listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month AS listing__created_at__extract_month - , subq_0.listing__created_at__extract_day AS listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow AS listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy AS listing__created_at__extract_doy - , subq_3.metric_time__day AS metric_time__day - , subq_0.listing AS listing - , subq_0.user AS user - , subq_0.listing__user AS listing__user - , subq_0.country_latest AS country_latest - , subq_0.is_lux_latest AS is_lux_latest - , subq_0.capacity_latest AS capacity_latest - , subq_0.listing__country_latest AS listing__country_latest - , subq_0.listing__is_lux_latest AS listing__is_lux_latest - , subq_0.listing__capacity_latest AS listing__capacity_latest - , subq_5.home_state_latest AS user__home_state_latest - , subq_0.listings AS listings - , subq_0.largest_listing AS largest_listing - , subq_0.smallest_listing AS smallest_listing + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 +CROSS JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['metric_time__day',] + SELECT + subq_1.ds__day AS metric_time__day FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - CROSS JOIN ( - -- Pass Only Elements: ['metric_time__day',] + -- Time Spine SELECT - subq_2.metric_time__day - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.ds__martian_day - , subq_1.ds__day AS metric_time__day - , subq_1.ds__week AS metric_time__week - , subq_1.ds__month AS metric_time__month - , subq_1.ds__quarter AS metric_time__quarter - , subq_1.ds__year AS metric_time__year - , subq_1.ds__extract_year AS metric_time__extract_year - , subq_1.ds__extract_quarter AS metric_time__extract_quarter - , subq_1.ds__extract_month AS metric_time__extract_month - , subq_1.ds__extract_day AS metric_time__extract_day - , subq_1.ds__extract_dow AS metric_time__extract_dow - , subq_1.ds__extract_doy AS metric_time__extract_doy - , subq_1.ds__martian_day AS metric_time__martian_day - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day - , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week - , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month - , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter - , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year - , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year - , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter - , EXTRACT(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_1 - ) subq_2 - ) subq_3 - FULL OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_4.user - , subq_4.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_4 - ) subq_5 - ON - subq_0.user = subq_5.user -) subq_6 + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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_1 +) subq_2 +FULL OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 +) subq_3 +ON + subq_0.user = subq_3.user GROUP BY - subq_6.metric_time__day - , subq_6.listing__is_lux_latest - , subq_6.user__home_state_latest + subq_2.metric_time__day + , subq_0.listing__is_lux_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_with_other_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_with_other_dimensions__plan0_optimized.sql index 68e7b122d2..bcc739d4b0 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_with_other_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/DuckDB/test_metric_time_with_other_dimensions__plan0_optimized.sql @@ -3,7 +3,6 @@ SELECT DATE_TRUNC('day', time_spine_src_28006.ds) AS metric_time__day , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 CROSS JOIN ***************************.mf_time_spine time_spine_src_28006 @@ -14,4 +13,3 @@ ON GROUP BY DATE_TRUNC('day', time_spine_src_28006.ds) , listings_latest_src_28000.is_lux - , users_latest_src_28000.home_state_latest diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_dimensions_with_time_constraint__plan0.xml b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_dimensions_with_time_constraint__plan0.xml index 03b3cc70a8..73a152b26a 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_dimensions_with_time_constraint__plan0.xml +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_dimensions_with_time_constraint__plan0.xml @@ -1,1014 +1,499 @@ - - + + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + - - + + - + - + - + - + - + - + - + - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_only__plan0.xml b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_only__plan0.xml index 0a7dd37ebd..548f32e7ad 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_only__plan0.xml +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_only__plan0.xml @@ -1,113 +1,37 @@ - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_quarter_alone__plan0.xml b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_quarter_alone__plan0.xml index 5cc53f4c4c..529a5957a0 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_quarter_alone__plan0.xml +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_quarter_alone__plan0.xml @@ -1,114 +1,38 @@ - + - - + + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + diff --git a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_with_other_dimensions__plan0.xml b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_with_other_dimensions__plan0.xml index b040c00dd5..ff7c8e1a1f 100644 --- a/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_with_other_dimensions__plan0.xml +++ b/tests_metricflow/snapshots/test_metric_time_without_metrics.py/SqlQueryPlan/test_metric_time_with_other_dimensions__plan0.xml @@ -1,742 +1,239 @@ - - + + + - + - - - - + + + + + + + + + + + + + + + - + - - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0.sql index b1a1412d9d..8e3a54c832 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0.sql @@ -1,632 +1,423 @@ -- Compute Metrics via Expressions SELECT - subq_27.metric_time__day - , subq_27.user__home_state_latest - , CAST(subq_27.buys AS DOUBLE) / CAST(NULLIF(subq_27.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days + subq_18.metric_time__day + , subq_18.user__home_state_latest + , CAST(subq_18.buys AS DOUBLE) / CAST(NULLIF(subq_18.visits, 0) AS DOUBLE) AS visit_buy_conversion_rate_7days FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) AS user__home_state_latest - , MAX(subq_9.visits) AS visits - , MAX(subq_26.buys) AS buys + COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) AS metric_time__day + , COALESCE(subq_5.user__home_state_latest, subq_17.user__home_state_latest) AS user__home_state_latest + , MAX(subq_5.visits) AS visits + , MAX(subq_17.buys) AS buys FROM ( -- Aggregate Measures SELECT - subq_8.metric_time__day - , subq_8.user__home_state_latest - , SUM(subq_8.visits) AS visits + subq_4.metric_time__day + , subq_4.user__home_state_latest + , SUM(subq_4.visits) AS visits FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.user__home_state_latest - , subq_7.visits + subq_3.metric_time__day + , subq_3.user__home_state_latest + , subq_3.visits FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.visit__referrer_id - , subq_6.user__home_state_latest - , subq_6.visits + subq_1.metric_time__day AS metric_time__day + , subq_1.visit__referrer_id AS visit__referrer_id + , subq_1.visits AS visits FROM ( - -- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['visits', 'visit__referrer_id', 'metric_time__day', 'user'] SELECT - subq_5.metric_time__day - , subq_5.visit__referrer_id - , subq_5.user__home_state_latest - , subq_5.visits + subq_0.ds__day AS metric_time__day + , subq_0.user + , subq_0.visit__referrer_id + , subq_0.visits FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.user AS user - , subq_2.visit__referrer_id AS visit__referrer_id - , subq_4.home_state_latest AS user__home_state_latest - , subq_2.visits AS visits - FROM ( - -- Pass Only Elements: ['visits', 'visit__referrer_id', 'metric_time__day', 'user'] - SELECT - subq_1.metric_time__day - , subq_1.user - , subq_1.visit__referrer_id - , subq_1.visits - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.visit__ds__day - , subq_0.visit__ds__week - , subq_0.visit__ds__month - , subq_0.visit__ds__quarter - , subq_0.visit__ds__year - , subq_0.visit__ds__extract_year - , subq_0.visit__ds__extract_quarter - , subq_0.visit__ds__extract_month - , subq_0.visit__ds__extract_day - , subq_0.visit__ds__extract_dow - , subq_0.visit__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.user - , subq_0.session - , subq_0.visit__user - , subq_0.visit__session - , subq_0.referrer_id - , subq_0.visit__referrer_id - , subq_0.visits - , subq_0.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_3.user - , subq_3.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_3 - ) subq_4 - ON - subq_2.user = subq_4.user - ) subq_5 - ) subq_6 - WHERE visit__referrer_id = '123456' - ) subq_7 - ) subq_8 + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_2 + ON + subq_1.user = subq_2.user + ) subq_3 + WHERE visit__referrer_id = '123456' + ) subq_4 GROUP BY - subq_8.metric_time__day - , subq_8.user__home_state_latest - ) subq_9 + subq_4.metric_time__day + , subq_4.user__home_state_latest + ) subq_5 FULL OUTER JOIN ( -- Aggregate Measures SELECT - subq_25.metric_time__day - , subq_25.user__home_state_latest - , SUM(subq_25.buys) AS buys + subq_16.metric_time__day + , subq_16.user__home_state_latest + , SUM(subq_16.buys) AS buys FROM ( + -- Join Standard Outputs -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day'] SELECT - subq_24.metric_time__day - , subq_24.user__home_state_latest - , subq_24.buys + subq_14.metric_time__day AS metric_time__day + , subq_14.buys AS buys FROM ( - -- Join Standard Outputs + -- Find conversions for user within the range of 7 day + -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user'] SELECT - subq_21.metric_time__day AS metric_time__day - , subq_21.user AS user - , subq_21.visit__referrer_id AS visit__referrer_id - , subq_23.home_state_latest AS user__home_state_latest - , subq_21.buys AS buys + subq_13.metric_time__day + , subq_13.user + , subq_13.visit__referrer_id + , subq_13.buys FROM ( - -- Pass Only Elements: ['buys', 'visit__referrer_id', 'metric_time__day', 'user'] - SELECT - subq_20.metric_time__day - , subq_20.user - , subq_20.visit__referrer_id - , subq_20.buys + -- Dedupe the fanout with mf_internal_uuid in the conversion data set + SELECT DISTINCT + FIRST_VALUE(subq_9.visits) OVER ( + PARTITION BY + subq_12.user + , subq_12.ds__day + , subq_12.mf_internal_uuid + ORDER BY subq_9.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visits + , FIRST_VALUE(subq_9.visit__referrer_id) OVER ( + PARTITION BY + subq_12.user + , subq_12.ds__day + , subq_12.mf_internal_uuid + ORDER BY subq_9.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS visit__referrer_id + , FIRST_VALUE(subq_9.user__home_state_latest) OVER ( + PARTITION BY + subq_12.user + , subq_12.ds__day + , subq_12.mf_internal_uuid + ORDER BY subq_9.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user__home_state_latest + , FIRST_VALUE(subq_9.ds__day) OVER ( + PARTITION BY + subq_12.user + , subq_12.ds__day + , subq_12.mf_internal_uuid + ORDER BY subq_9.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS ds__day + , FIRST_VALUE(subq_9.metric_time__day) OVER ( + PARTITION BY + subq_12.user + , subq_12.ds__day + , subq_12.mf_internal_uuid + ORDER BY subq_9.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS metric_time__day + , FIRST_VALUE(subq_9.user) OVER ( + PARTITION BY + subq_12.user + , subq_12.ds__day + , subq_12.mf_internal_uuid + ORDER BY subq_9.ds__day DESC + ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING + ) AS user + , subq_12.mf_internal_uuid AS mf_internal_uuid + , subq_12.buys AS buys FROM ( - -- Find conversions for user within the range of 7 day + -- Join Standard Outputs + -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user'] SELECT - subq_19.ds__day - , subq_19.metric_time__day - , subq_19.user - , subq_19.visit__referrer_id - , subq_19.user__home_state_latest - , subq_19.buys - , subq_19.visits + subq_7.ds__day AS ds__day + , subq_7.metric_time__day AS metric_time__day + , subq_7.user AS user + , subq_7.visit__referrer_id AS visit__referrer_id + , subq_7.visits AS visits FROM ( - -- Dedupe the fanout with mf_internal_uuid in the conversion data set - SELECT DISTINCT - FIRST_VALUE(subq_15.visits) OVER ( - PARTITION BY - subq_18.user - , subq_18.ds__day - , subq_18.mf_internal_uuid - ORDER BY subq_15.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visits - , FIRST_VALUE(subq_15.visit__referrer_id) OVER ( - PARTITION BY - subq_18.user - , subq_18.ds__day - , subq_18.mf_internal_uuid - ORDER BY subq_15.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS visit__referrer_id - , FIRST_VALUE(subq_15.user__home_state_latest) OVER ( - PARTITION BY - subq_18.user - , subq_18.ds__day - , subq_18.mf_internal_uuid - ORDER BY subq_15.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user__home_state_latest - , FIRST_VALUE(subq_15.ds__day) OVER ( - PARTITION BY - subq_18.user - , subq_18.ds__day - , subq_18.mf_internal_uuid - ORDER BY subq_15.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS ds__day - , FIRST_VALUE(subq_15.metric_time__day) OVER ( - PARTITION BY - subq_18.user - , subq_18.ds__day - , subq_18.mf_internal_uuid - ORDER BY subq_15.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS metric_time__day - , FIRST_VALUE(subq_15.user) OVER ( - PARTITION BY - subq_18.user - , subq_18.ds__day - , subq_18.mf_internal_uuid - ORDER BY subq_15.ds__day DESC - ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING - ) AS user - , subq_18.mf_internal_uuid AS mf_internal_uuid - , subq_18.buys AS buys + -- Metric Time Dimension 'ds' + SELECT + subq_6.ds__day + , subq_6.ds__week + , subq_6.ds__month + , subq_6.ds__quarter + , subq_6.ds__year + , subq_6.ds__extract_year + , subq_6.ds__extract_quarter + , subq_6.ds__extract_month + , subq_6.ds__extract_day + , subq_6.ds__extract_dow + , subq_6.ds__extract_doy + , subq_6.visit__ds__day + , subq_6.visit__ds__week + , subq_6.visit__ds__month + , subq_6.visit__ds__quarter + , subq_6.visit__ds__year + , subq_6.visit__ds__extract_year + , subq_6.visit__ds__extract_quarter + , subq_6.visit__ds__extract_month + , subq_6.visit__ds__extract_day + , subq_6.visit__ds__extract_dow + , subq_6.visit__ds__extract_doy + , subq_6.ds__day AS metric_time__day + , subq_6.ds__week AS metric_time__week + , subq_6.ds__month AS metric_time__month + , subq_6.ds__quarter AS metric_time__quarter + , subq_6.ds__year AS metric_time__year + , subq_6.ds__extract_year AS metric_time__extract_year + , subq_6.ds__extract_quarter AS metric_time__extract_quarter + , subq_6.ds__extract_month AS metric_time__extract_month + , subq_6.ds__extract_day AS metric_time__extract_day + , subq_6.ds__extract_dow AS metric_time__extract_dow + , subq_6.ds__extract_doy AS metric_time__extract_doy + , subq_6.user + , subq_6.session + , subq_6.visit__user + , subq_6.visit__session + , subq_6.referrer_id + , subq_6.visit__referrer_id + , subq_6.visits + , subq_6.visitors FROM ( - -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user'] - SELECT - subq_14.ds__day - , subq_14.metric_time__day - , subq_14.user - , subq_14.visit__referrer_id - , subq_14.user__home_state_latest - , subq_14.visits - FROM ( - -- Join Standard Outputs - SELECT - subq_11.ds__day AS ds__day - , subq_11.ds__week AS ds__week - , subq_11.ds__month AS ds__month - , subq_11.ds__quarter AS ds__quarter - , subq_11.ds__year AS ds__year - , subq_11.ds__extract_year AS ds__extract_year - , subq_11.ds__extract_quarter AS ds__extract_quarter - , subq_11.ds__extract_month AS ds__extract_month - , subq_11.ds__extract_day AS ds__extract_day - , subq_11.ds__extract_dow AS ds__extract_dow - , subq_11.ds__extract_doy AS ds__extract_doy - , subq_11.visit__ds__day AS visit__ds__day - , subq_11.visit__ds__week AS visit__ds__week - , subq_11.visit__ds__month AS visit__ds__month - , subq_11.visit__ds__quarter AS visit__ds__quarter - , subq_11.visit__ds__year AS visit__ds__year - , subq_11.visit__ds__extract_year AS visit__ds__extract_year - , subq_11.visit__ds__extract_quarter AS visit__ds__extract_quarter - , subq_11.visit__ds__extract_month AS visit__ds__extract_month - , subq_11.visit__ds__extract_day AS visit__ds__extract_day - , subq_11.visit__ds__extract_dow AS visit__ds__extract_dow - , subq_11.visit__ds__extract_doy AS visit__ds__extract_doy - , subq_11.metric_time__day AS metric_time__day - , subq_11.metric_time__week AS metric_time__week - , subq_11.metric_time__month AS metric_time__month - , subq_11.metric_time__quarter AS metric_time__quarter - , subq_11.metric_time__year AS metric_time__year - , subq_11.metric_time__extract_year AS metric_time__extract_year - , subq_11.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_11.metric_time__extract_month AS metric_time__extract_month - , subq_11.metric_time__extract_day AS metric_time__extract_day - , subq_11.metric_time__extract_dow AS metric_time__extract_dow - , subq_11.metric_time__extract_doy AS metric_time__extract_doy - , subq_11.user AS user - , subq_11.session AS session - , subq_11.visit__user AS visit__user - , subq_11.visit__session AS visit__session - , subq_11.referrer_id AS referrer_id - , subq_11.visit__referrer_id AS visit__referrer_id - , subq_13.home_state_latest AS user__home_state_latest - , subq_11.visits AS visits - , subq_11.visitors AS visitors - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_10.ds__day - , subq_10.ds__week - , subq_10.ds__month - , subq_10.ds__quarter - , subq_10.ds__year - , subq_10.ds__extract_year - , subq_10.ds__extract_quarter - , subq_10.ds__extract_month - , subq_10.ds__extract_day - , subq_10.ds__extract_dow - , subq_10.ds__extract_doy - , subq_10.visit__ds__day - , subq_10.visit__ds__week - , subq_10.visit__ds__month - , subq_10.visit__ds__quarter - , subq_10.visit__ds__year - , subq_10.visit__ds__extract_year - , subq_10.visit__ds__extract_quarter - , subq_10.visit__ds__extract_month - , subq_10.visit__ds__extract_day - , subq_10.visit__ds__extract_dow - , subq_10.visit__ds__extract_doy - , subq_10.ds__day AS metric_time__day - , subq_10.ds__week AS metric_time__week - , subq_10.ds__month AS metric_time__month - , subq_10.ds__quarter AS metric_time__quarter - , subq_10.ds__year AS metric_time__year - , subq_10.ds__extract_year AS metric_time__extract_year - , subq_10.ds__extract_quarter AS metric_time__extract_quarter - , subq_10.ds__extract_month AS metric_time__extract_month - , subq_10.ds__extract_day AS metric_time__extract_day - , subq_10.ds__extract_dow AS metric_time__extract_dow - , subq_10.ds__extract_doy AS metric_time__extract_doy - , subq_10.user - , subq_10.session - , subq_10.visit__user - , subq_10.visit__session - , subq_10.referrer_id - , subq_10.visit__referrer_id - , subq_10.visits - , subq_10.visitors - FROM ( - -- Read Elements From Semantic Model 'visits_source' - SELECT - 1 AS visits - , visits_source_src_28000.user_id AS visitors - , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy - , visits_source_src_28000.referrer_id - , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day - , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week - , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month - , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter - , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year - , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year - , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter - , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month - , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day - , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow - , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy - , visits_source_src_28000.referrer_id AS visit__referrer_id - , visits_source_src_28000.user_id AS user - , visits_source_src_28000.session_id AS session - , visits_source_src_28000.user_id AS visit__user - , visits_source_src_28000.session_id AS visit__session - FROM ***************************.fct_visits visits_source_src_28000 - ) subq_10 - ) subq_11 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_12.user - , subq_12.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_12 - ) subq_13 - ON - subq_11.user = subq_13.user - ) subq_14 - ) subq_15 - INNER JOIN ( - -- Add column with generated UUID + -- Read Elements From Semantic Model 'visits_source' SELECT - subq_17.ds__day - , subq_17.ds__week - , subq_17.ds__month - , subq_17.ds__quarter - , subq_17.ds__year - , subq_17.ds__extract_year - , subq_17.ds__extract_quarter - , subq_17.ds__extract_month - , subq_17.ds__extract_day - , subq_17.ds__extract_dow - , subq_17.ds__extract_doy - , subq_17.buy__ds__day - , subq_17.buy__ds__week - , subq_17.buy__ds__month - , subq_17.buy__ds__quarter - , subq_17.buy__ds__year - , subq_17.buy__ds__extract_year - , subq_17.buy__ds__extract_quarter - , subq_17.buy__ds__extract_month - , subq_17.buy__ds__extract_day - , subq_17.buy__ds__extract_dow - , subq_17.buy__ds__extract_doy - , subq_17.metric_time__day - , subq_17.metric_time__week - , subq_17.metric_time__month - , subq_17.metric_time__quarter - , subq_17.metric_time__year - , subq_17.metric_time__extract_year - , subq_17.metric_time__extract_quarter - , subq_17.metric_time__extract_month - , subq_17.metric_time__extract_day - , subq_17.metric_time__extract_dow - , subq_17.metric_time__extract_doy - , subq_17.user - , subq_17.session_id - , subq_17.buy__user - , subq_17.buy__session_id - , subq_17.buys - , subq_17.buyers - , GEN_RANDOM_UUID() AS mf_internal_uuid - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_16.ds__day - , subq_16.ds__week - , subq_16.ds__month - , subq_16.ds__quarter - , subq_16.ds__year - , subq_16.ds__extract_year - , subq_16.ds__extract_quarter - , subq_16.ds__extract_month - , subq_16.ds__extract_day - , subq_16.ds__extract_dow - , subq_16.ds__extract_doy - , subq_16.buy__ds__day - , subq_16.buy__ds__week - , subq_16.buy__ds__month - , subq_16.buy__ds__quarter - , subq_16.buy__ds__year - , subq_16.buy__ds__extract_year - , subq_16.buy__ds__extract_quarter - , subq_16.buy__ds__extract_month - , subq_16.buy__ds__extract_day - , subq_16.buy__ds__extract_dow - , subq_16.buy__ds__extract_doy - , subq_16.ds__day AS metric_time__day - , subq_16.ds__week AS metric_time__week - , subq_16.ds__month AS metric_time__month - , subq_16.ds__quarter AS metric_time__quarter - , subq_16.ds__year AS metric_time__year - , subq_16.ds__extract_year AS metric_time__extract_year - , subq_16.ds__extract_quarter AS metric_time__extract_quarter - , subq_16.ds__extract_month AS metric_time__extract_month - , subq_16.ds__extract_day AS metric_time__extract_day - , subq_16.ds__extract_dow AS metric_time__extract_dow - , subq_16.ds__extract_doy AS metric_time__extract_doy - , subq_16.user - , subq_16.session_id - , subq_16.buy__user - , subq_16.buy__session_id - , subq_16.buys - , subq_16.buyers - FROM ( - -- Read Elements From Semantic Model 'buys_source' - SELECT - 1 AS buys - , buys_source_src_28000.user_id AS buyers - , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day - , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week - , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month - , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter - , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year - , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year - , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter - , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month - , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day - , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow - , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy - , buys_source_src_28000.user_id AS user - , buys_source_src_28000.session_id - , buys_source_src_28000.user_id AS buy__user - , buys_source_src_28000.session_id AS buy__session_id - FROM ***************************.fct_buys buys_source_src_28000 - ) subq_16 - ) subq_17 - ) subq_18 - ON - ( - subq_15.user = subq_18.user - ) AND ( - ( - subq_15.ds__day <= subq_18.ds__day - ) AND ( - subq_15.ds__day > subq_18.ds__day - INTERVAL 7 day - ) - ) - ) subq_19 - ) subq_20 - ) subq_21 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_22.user - , subq_22.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' + 1 AS visits + , visits_source_src_28000.user_id AS visitors + , DATE_TRUNC('day', visits_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS ds__extract_doy + , visits_source_src_28000.referrer_id + , DATE_TRUNC('day', visits_source_src_28000.ds) AS visit__ds__day + , DATE_TRUNC('week', visits_source_src_28000.ds) AS visit__ds__week + , DATE_TRUNC('month', visits_source_src_28000.ds) AS visit__ds__month + , DATE_TRUNC('quarter', visits_source_src_28000.ds) AS visit__ds__quarter + , DATE_TRUNC('year', visits_source_src_28000.ds) AS visit__ds__year + , EXTRACT(year FROM visits_source_src_28000.ds) AS visit__ds__extract_year + , EXTRACT(quarter FROM visits_source_src_28000.ds) AS visit__ds__extract_quarter + , EXTRACT(month FROM visits_source_src_28000.ds) AS visit__ds__extract_month + , EXTRACT(day FROM visits_source_src_28000.ds) AS visit__ds__extract_day + , EXTRACT(isodow FROM visits_source_src_28000.ds) AS visit__ds__extract_dow + , EXTRACT(doy FROM visits_source_src_28000.ds) AS visit__ds__extract_doy + , visits_source_src_28000.referrer_id AS visit__referrer_id + , visits_source_src_28000.user_id AS user + , visits_source_src_28000.session_id AS session + , visits_source_src_28000.user_id AS visit__user + , visits_source_src_28000.session_id AS visit__session + FROM ***************************.fct_visits visits_source_src_28000 + ) subq_6 + ) subq_7 + LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_8 + ON + subq_7.user = subq_8.user + ) subq_9 + INNER JOIN ( + -- Add column with generated UUID SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_22 - ) subq_23 - ON - subq_21.user = subq_23.user - ) subq_24 - ) subq_25 + subq_11.ds__day + , subq_11.ds__week + , subq_11.ds__month + , subq_11.ds__quarter + , subq_11.ds__year + , subq_11.ds__extract_year + , subq_11.ds__extract_quarter + , subq_11.ds__extract_month + , subq_11.ds__extract_day + , subq_11.ds__extract_dow + , subq_11.ds__extract_doy + , subq_11.buy__ds__day + , subq_11.buy__ds__week + , subq_11.buy__ds__month + , subq_11.buy__ds__quarter + , subq_11.buy__ds__year + , subq_11.buy__ds__extract_year + , subq_11.buy__ds__extract_quarter + , subq_11.buy__ds__extract_month + , subq_11.buy__ds__extract_day + , subq_11.buy__ds__extract_dow + , subq_11.buy__ds__extract_doy + , subq_11.metric_time__day + , subq_11.metric_time__week + , subq_11.metric_time__month + , subq_11.metric_time__quarter + , subq_11.metric_time__year + , subq_11.metric_time__extract_year + , subq_11.metric_time__extract_quarter + , subq_11.metric_time__extract_month + , subq_11.metric_time__extract_day + , subq_11.metric_time__extract_dow + , subq_11.metric_time__extract_doy + , subq_11.user + , subq_11.session_id + , subq_11.buy__user + , subq_11.buy__session_id + , subq_11.buys + , subq_11.buyers + , GEN_RANDOM_UUID() AS mf_internal_uuid + FROM ( + -- Metric Time Dimension 'ds' + SELECT + subq_10.ds__day + , subq_10.ds__week + , subq_10.ds__month + , subq_10.ds__quarter + , subq_10.ds__year + , subq_10.ds__extract_year + , subq_10.ds__extract_quarter + , subq_10.ds__extract_month + , subq_10.ds__extract_day + , subq_10.ds__extract_dow + , subq_10.ds__extract_doy + , subq_10.buy__ds__day + , subq_10.buy__ds__week + , subq_10.buy__ds__month + , subq_10.buy__ds__quarter + , subq_10.buy__ds__year + , subq_10.buy__ds__extract_year + , subq_10.buy__ds__extract_quarter + , subq_10.buy__ds__extract_month + , subq_10.buy__ds__extract_day + , subq_10.buy__ds__extract_dow + , subq_10.buy__ds__extract_doy + , subq_10.ds__day AS metric_time__day + , subq_10.ds__week AS metric_time__week + , subq_10.ds__month AS metric_time__month + , subq_10.ds__quarter AS metric_time__quarter + , subq_10.ds__year AS metric_time__year + , subq_10.ds__extract_year AS metric_time__extract_year + , subq_10.ds__extract_quarter AS metric_time__extract_quarter + , subq_10.ds__extract_month AS metric_time__extract_month + , subq_10.ds__extract_day AS metric_time__extract_day + , subq_10.ds__extract_dow AS metric_time__extract_dow + , subq_10.ds__extract_doy AS metric_time__extract_doy + , subq_10.user + , subq_10.session_id + , subq_10.buy__user + , subq_10.buy__session_id + , subq_10.buys + , subq_10.buyers + FROM ( + -- Read Elements From Semantic Model 'buys_source' + SELECT + 1 AS buys + , buys_source_src_28000.user_id AS buyers + , DATE_TRUNC('day', buys_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', buys_source_src_28000.ds) AS buy__ds__day + , DATE_TRUNC('week', buys_source_src_28000.ds) AS buy__ds__week + , DATE_TRUNC('month', buys_source_src_28000.ds) AS buy__ds__month + , DATE_TRUNC('quarter', buys_source_src_28000.ds) AS buy__ds__quarter + , DATE_TRUNC('year', buys_source_src_28000.ds) AS buy__ds__year + , EXTRACT(year FROM buys_source_src_28000.ds) AS buy__ds__extract_year + , EXTRACT(quarter FROM buys_source_src_28000.ds) AS buy__ds__extract_quarter + , EXTRACT(month FROM buys_source_src_28000.ds) AS buy__ds__extract_month + , EXTRACT(day FROM buys_source_src_28000.ds) AS buy__ds__extract_day + , EXTRACT(isodow FROM buys_source_src_28000.ds) AS buy__ds__extract_dow + , EXTRACT(doy FROM buys_source_src_28000.ds) AS buy__ds__extract_doy + , buys_source_src_28000.user_id AS user + , buys_source_src_28000.session_id + , buys_source_src_28000.user_id AS buy__user + , buys_source_src_28000.session_id AS buy__session_id + FROM ***************************.fct_buys buys_source_src_28000 + ) subq_10 + ) subq_11 + ) subq_12 + ON + ( + subq_9.user = subq_12.user + ) AND ( + ( + subq_9.ds__day <= subq_12.ds__day + ) AND ( + subq_9.ds__day > subq_12.ds__day - INTERVAL 7 day + ) + ) + ) subq_13 + ) subq_14 + LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_15 + ON + subq_14.user = subq_15.user + ) subq_16 GROUP BY - subq_25.metric_time__day - , subq_25.user__home_state_latest - ) subq_26 + subq_16.metric_time__day + , subq_16.user__home_state_latest + ) subq_17 ON ( - subq_9.user__home_state_latest = subq_26.user__home_state_latest + subq_5.user__home_state_latest = subq_17.user__home_state_latest ) AND ( - subq_9.metric_time__day = subq_26.metric_time__day + subq_5.metric_time__day = subq_17.metric_time__day ) GROUP BY - COALESCE(subq_9.metric_time__day, subq_26.metric_time__day) - , COALESCE(subq_9.user__home_state_latest, subq_26.user__home_state_latest) -) subq_27 + COALESCE(subq_5.metric_time__day, subq_17.metric_time__day) + , COALESCE(subq_5.user__home_state_latest, subq_17.user__home_state_latest) +) subq_18 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0_optimized.sql index 61e0c5aeec..0cf4b197ef 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_conversion_metric_query_filters__plan0_optimized.sql @@ -6,10 +6,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) AS metric_time__day - , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) AS user__home_state_latest - , MAX(subq_37.visits) AS visits - , MAX(subq_54.buys) AS buys + COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) AS metric_time__day + , COALESCE(subq_24.user__home_state_latest, subq_36.user__home_state_latest) AS user__home_state_latest + , MAX(subq_24.visits) AS visits + , MAX(subq_36.buys) AS buys FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['visits', 'user__home_state_latest', 'metric_time__day'] @@ -22,10 +22,9 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['visits', 'user__home_state_latest', 'visit__referrer_id', 'metric_time__day'] SELECT - subq_30.metric_time__day AS metric_time__day - , subq_30.visit__referrer_id AS visit__referrer_id - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , subq_30.visits AS visits + subq_20.metric_time__day AS metric_time__day + , subq_20.visit__referrer_id AS visit__referrer_id + , subq_20.visits AS visits FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -36,88 +35,87 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_30 + ) subq_20 LEFT OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - subq_30.user = users_latest_src_28000.user_id - ) subq_34 + subq_20.user = users_latest_src_28000.user_id + ) subq_22 WHERE visit__referrer_id = '123456' GROUP BY metric_time__day , user__home_state_latest - ) subq_37 + ) subq_24 FULL OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['buys', 'user__home_state_latest', 'metric_time__day'] -- Aggregate Measures SELECT - subq_47.metric_time__day AS metric_time__day - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , SUM(subq_47.buys) AS buys + subq_32.metric_time__day AS metric_time__day + , subq_35.user__home_state_latest AS user__home_state_latest + , SUM(subq_32.buys) AS buys FROM ( -- Dedupe the fanout with mf_internal_uuid in the conversion data set SELECT DISTINCT - FIRST_VALUE(subq_43.visits) OVER ( + FIRST_VALUE(subq_28.visits) OVER ( PARTITION BY - subq_46.user - , subq_46.ds__day - , subq_46.mf_internal_uuid - ORDER BY subq_43.ds__day DESC + subq_31.user + , subq_31.ds__day + , subq_31.mf_internal_uuid + ORDER BY subq_28.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visits - , FIRST_VALUE(subq_43.visit__referrer_id) OVER ( + , FIRST_VALUE(subq_28.visit__referrer_id) OVER ( PARTITION BY - subq_46.user - , subq_46.ds__day - , subq_46.mf_internal_uuid - ORDER BY subq_43.ds__day DESC + subq_31.user + , subq_31.ds__day + , subq_31.mf_internal_uuid + ORDER BY subq_28.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS visit__referrer_id - , FIRST_VALUE(subq_43.user__home_state_latest) OVER ( + , FIRST_VALUE(subq_28.user__home_state_latest) OVER ( PARTITION BY - subq_46.user - , subq_46.ds__day - , subq_46.mf_internal_uuid - ORDER BY subq_43.ds__day DESC + subq_31.user + , subq_31.ds__day + , subq_31.mf_internal_uuid + ORDER BY subq_28.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user__home_state_latest - , FIRST_VALUE(subq_43.ds__day) OVER ( + , FIRST_VALUE(subq_28.ds__day) OVER ( PARTITION BY - subq_46.user - , subq_46.ds__day - , subq_46.mf_internal_uuid - ORDER BY subq_43.ds__day DESC + subq_31.user + , subq_31.ds__day + , subq_31.mf_internal_uuid + ORDER BY subq_28.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS ds__day - , FIRST_VALUE(subq_43.metric_time__day) OVER ( + , FIRST_VALUE(subq_28.metric_time__day) OVER ( PARTITION BY - subq_46.user - , subq_46.ds__day - , subq_46.mf_internal_uuid - ORDER BY subq_43.ds__day DESC + subq_31.user + , subq_31.ds__day + , subq_31.mf_internal_uuid + ORDER BY subq_28.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS metric_time__day - , FIRST_VALUE(subq_43.user) OVER ( + , FIRST_VALUE(subq_28.user) OVER ( PARTITION BY - subq_46.user - , subq_46.ds__day - , subq_46.mf_internal_uuid - ORDER BY subq_43.ds__day DESC + subq_31.user + , subq_31.ds__day + , subq_31.mf_internal_uuid + ORDER BY subq_28.ds__day DESC ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING ) AS user - , subq_46.mf_internal_uuid AS mf_internal_uuid - , subq_46.buys AS buys + , subq_31.mf_internal_uuid AS mf_internal_uuid + , subq_31.buys AS buys FROM ( -- Join Standard Outputs -- Pass Only Elements: ['visits', 'visit__referrer_id', 'user__home_state_latest', 'ds__day', 'metric_time__day', 'user'] SELECT - subq_39.ds__day AS ds__day - , subq_39.metric_time__day AS metric_time__day - , subq_39.user AS user - , subq_39.visit__referrer_id AS visit__referrer_id - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , subq_39.visits AS visits + subq_26.ds__day AS ds__day + , subq_26.metric_time__day AS metric_time__day + , subq_26.user AS user + , subq_26.visit__referrer_id AS visit__referrer_id + , subq_26.visits AS visits FROM ( -- Read Elements From Semantic Model 'visits_source' -- Metric Time Dimension 'ds' @@ -128,12 +126,12 @@ FROM ( , referrer_id AS visit__referrer_id , 1 AS visits FROM ***************************.fct_visits visits_source_src_28000 - ) subq_39 + ) subq_26 LEFT OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - subq_39.user = users_latest_src_28000.user_id - ) subq_43 + subq_26.user = users_latest_src_28000.user_id + ) subq_28 INNER JOIN ( -- Read Elements From Semantic Model 'buys_source' -- Metric Time Dimension 'ds' @@ -144,33 +142,33 @@ FROM ( , 1 AS buys , GEN_RANDOM_UUID() AS mf_internal_uuid FROM ***************************.fct_buys buys_source_src_28000 - ) subq_46 + ) subq_31 ON ( - subq_43.user = subq_46.user + subq_28.user = subq_31.user ) AND ( ( - subq_43.ds__day <= subq_46.ds__day + subq_28.ds__day <= subq_31.ds__day ) AND ( - subq_43.ds__day > subq_46.ds__day - INTERVAL 7 day + subq_28.ds__day > subq_31.ds__day - INTERVAL 7 day ) ) - ) subq_47 + ) subq_32 LEFT OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - subq_47.user = users_latest_src_28000.user_id + subq_32.user = users_latest_src_28000.user_id GROUP BY - subq_47.metric_time__day - , users_latest_src_28000.home_state_latest - ) subq_54 + subq_32.metric_time__day + , subq_35.user__home_state_latest + ) subq_36 ON ( - subq_37.user__home_state_latest = subq_54.user__home_state_latest + subq_24.user__home_state_latest = subq_36.user__home_state_latest ) AND ( - subq_37.metric_time__day = subq_54.metric_time__day + subq_24.metric_time__day = subq_36.metric_time__day ) GROUP BY - COALESCE(subq_37.metric_time__day, subq_54.metric_time__day) - , COALESCE(subq_37.user__home_state_latest, subq_54.user__home_state_latest) -) subq_55 + COALESCE(subq_24.metric_time__day, subq_36.metric_time__day) + , COALESCE(subq_24.user__home_state_latest, subq_36.user__home_state_latest) +) subq_37 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0.sql index 48a9f31b84..d093bd0c71 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0.sql @@ -1,505 +1,318 @@ -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.listing__country_latest - , subq_13.bookers AS every_two_days_bookers + subq_9.metric_time__day + , subq_9.listing__country_latest + , subq_9.bookers AS every_two_days_bookers FROM ( -- Aggregate Measures SELECT - subq_12.metric_time__day - , subq_12.listing__country_latest - , COUNT(DISTINCT subq_12.bookers) AS bookers + subq_8.metric_time__day + , subq_8.listing__country_latest + , COUNT(DISTINCT subq_8.bookers) AS bookers FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookers', 'listing__country_latest', 'metric_time__day'] SELECT - subq_11.metric_time__day - , subq_11.listing__country_latest - , subq_11.bookers + subq_7.metric_time__day + , subq_7.listing__country_latest + , subq_7.bookers FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookers', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_10.metric_time__day - , subq_10.booking__is_instant - , subq_10.listing__country_latest - , subq_10.bookers + subq_4.metric_time__day AS metric_time__day + , subq_4.booking__is_instant AS booking__is_instant + , subq_4.bookers AS bookers FROM ( - -- Pass Only Elements: ['bookers', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] + -- Join Self Over Time Range + -- Pass Only Elements: ['bookers', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_9.metric_time__day - , subq_9.booking__is_instant - , subq_9.listing__country_latest - , subq_9.bookers + subq_2.metric_time__day AS metric_time__day + , subq_1.listing AS listing + , subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookers AS bookers FROM ( - -- Join Standard Outputs + -- Time Spine SELECT - subq_5.metric_time__day AS metric_time__day - , subq_5.listing AS listing - , subq_5.booking__is_instant AS booking__is_instant - , subq_8.country_latest AS listing__country_latest - , subq_5.bookers AS bookers + subq_3.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_3 + ) subq_2 + INNER JOIN ( + -- Metric Time Dimension 'ds' + SELECT + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Pass Only Elements: ['bookers', 'booking__is_instant', 'metric_time__day', 'listing'] - SELECT - subq_4.metric_time__day - , subq_4.listing - , subq_4.booking__is_instant - , subq_4.bookers - FROM ( - -- Join Self Over Time Range - SELECT - subq_2.metric_time__day AS metric_time__day - , subq_1.ds__day AS ds__day - , subq_1.ds__week AS ds__week - , subq_1.ds__month AS ds__month - , subq_1.ds__quarter AS ds__quarter - , subq_1.ds__year AS ds__year - , subq_1.ds__extract_year AS ds__extract_year - , subq_1.ds__extract_quarter AS ds__extract_quarter - , subq_1.ds__extract_month AS ds__extract_month - , subq_1.ds__extract_day AS ds__extract_day - , subq_1.ds__extract_dow AS ds__extract_dow - , subq_1.ds__extract_doy AS ds__extract_doy - , subq_1.ds_partitioned__day AS ds_partitioned__day - , subq_1.ds_partitioned__week AS ds_partitioned__week - , subq_1.ds_partitioned__month AS ds_partitioned__month - , subq_1.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_1.ds_partitioned__year AS ds_partitioned__year - , subq_1.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_1.paid_at__day AS paid_at__day - , subq_1.paid_at__week AS paid_at__week - , subq_1.paid_at__month AS paid_at__month - , subq_1.paid_at__quarter AS paid_at__quarter - , subq_1.paid_at__year AS paid_at__year - , subq_1.paid_at__extract_year AS paid_at__extract_year - , subq_1.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_1.paid_at__extract_month AS paid_at__extract_month - , subq_1.paid_at__extract_day AS paid_at__extract_day - , subq_1.paid_at__extract_dow AS paid_at__extract_dow - , subq_1.paid_at__extract_doy AS paid_at__extract_doy - , subq_1.booking__ds__day AS booking__ds__day - , subq_1.booking__ds__week AS booking__ds__week - , subq_1.booking__ds__month AS booking__ds__month - , subq_1.booking__ds__quarter AS booking__ds__quarter - , subq_1.booking__ds__year AS booking__ds__year - , subq_1.booking__ds__extract_year AS booking__ds__extract_year - , subq_1.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_1.booking__ds__extract_month AS booking__ds__extract_month - , subq_1.booking__ds__extract_day AS booking__ds__extract_day - , subq_1.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_1.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day AS booking__paid_at__day - , subq_1.booking__paid_at__week AS booking__paid_at__week - , subq_1.booking__paid_at__month AS booking__paid_at__month - , subq_1.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_1.booking__paid_at__year AS booking__paid_at__year - , subq_1.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_1.metric_time__week AS metric_time__week - , subq_1.metric_time__month AS metric_time__month - , subq_1.metric_time__quarter AS metric_time__quarter - , subq_1.metric_time__year AS metric_time__year - , 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_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_1.listing AS listing - , subq_1.guest AS guest - , subq_1.host AS host - , subq_1.booking__listing AS booking__listing - , subq_1.booking__guest AS booking__guest - , subq_1.booking__host AS booking__host - , subq_1.is_instant AS is_instant - , subq_1.booking__is_instant AS booking__is_instant - , subq_1.bookings AS bookings - , subq_1.instant_bookings AS instant_bookings - , subq_1.booking_value AS booking_value - , subq_1.max_booking_value AS max_booking_value - , subq_1.min_booking_value AS min_booking_value - , subq_1.bookers AS bookers - , subq_1.average_booking_value AS average_booking_value - , subq_1.referred_bookings AS referred_bookings - , subq_1.median_booking_value AS median_booking_value - , subq_1.booking_value_p99 AS booking_value_p99 - , 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 - FROM ( - -- Time Spine - SELECT - subq_3.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_3 - ) subq_2 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ON - ( - subq_1.metric_time__day <= subq_2.metric_time__day - ) AND ( - subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day - ) - ) subq_4 - ) subq_5 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_7.listing - , subq_7.country_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.created_at__day - , subq_6.created_at__week - , subq_6.created_at__month - , subq_6.created_at__quarter - , subq_6.created_at__year - , subq_6.created_at__extract_year - , subq_6.created_at__extract_quarter - , subq_6.created_at__extract_month - , subq_6.created_at__extract_day - , subq_6.created_at__extract_dow - , subq_6.created_at__extract_doy - , subq_6.listing__ds__day - , subq_6.listing__ds__week - , subq_6.listing__ds__month - , subq_6.listing__ds__quarter - , subq_6.listing__ds__year - , subq_6.listing__ds__extract_year - , subq_6.listing__ds__extract_quarter - , subq_6.listing__ds__extract_month - , subq_6.listing__ds__extract_day - , subq_6.listing__ds__extract_dow - , subq_6.listing__ds__extract_doy - , subq_6.listing__created_at__day - , subq_6.listing__created_at__week - , subq_6.listing__created_at__month - , subq_6.listing__created_at__quarter - , subq_6.listing__created_at__year - , subq_6.listing__created_at__extract_year - , subq_6.listing__created_at__extract_quarter - , subq_6.listing__created_at__extract_month - , subq_6.listing__created_at__extract_day - , subq_6.listing__created_at__extract_dow - , subq_6.listing__created_at__extract_doy - , subq_6.ds__day AS metric_time__day - , subq_6.ds__week AS metric_time__week - , subq_6.ds__month AS metric_time__month - , subq_6.ds__quarter AS metric_time__quarter - , subq_6.ds__year AS metric_time__year - , subq_6.ds__extract_year AS metric_time__extract_year - , subq_6.ds__extract_quarter AS metric_time__extract_quarter - , subq_6.ds__extract_month AS metric_time__extract_month - , subq_6.ds__extract_day AS metric_time__extract_day - , subq_6.ds__extract_dow AS metric_time__extract_dow - , subq_6.ds__extract_doy AS metric_time__extract_doy - , subq_6.listing - , subq_6.user - , subq_6.listing__user - , subq_6.country_latest - , subq_6.is_lux_latest - , subq_6.capacity_latest - , subq_6.listing__country_latest - , subq_6.listing__is_lux_latest - , subq_6.listing__capacity_latest - , subq_6.listings - , subq_6.largest_listing - , subq_6.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_6 - ) subq_7 - ) subq_8 - ON - subq_5.listing = subq_8.listing - ) subq_9 - ) subq_10 - WHERE booking__is_instant - ) subq_11 - ) subq_12 + 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 + ) subq_1 + ON + ( + subq_1.metric_time__day <= subq_2.metric_time__day + ) AND ( + subq_1.metric_time__day > subq_2.metric_time__day - INTERVAL 2 day + ) + ) subq_4 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_5.listing + , subq_5.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_5 + ) subq_6 + ON + subq_4.listing = subq_6.listing + ) subq_7 + WHERE booking__is_instant + ) subq_8 GROUP BY - subq_12.metric_time__day - , subq_12.listing__country_latest -) subq_13 + subq_8.metric_time__day + , subq_8.listing__country_latest +) subq_9 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0_optimized.sql index e1192adce6..075eff4f2d 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_cumulative_metric_with_query_time_filters__plan0_optimized.sql @@ -10,33 +10,32 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookers', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_19.metric_time__day AS metric_time__day - , subq_19.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.country AS listing__country_latest - , subq_19.bookers AS bookers + subq_14.metric_time__day AS metric_time__day + , subq_14.booking__is_instant AS booking__is_instant + , subq_14.bookers AS bookers FROM ( -- Join Self Over Time Range -- Pass Only Elements: ['bookers', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_17.ds AS metric_time__day + subq_13.ds AS metric_time__day , bookings_source_src_28000.listing_id AS listing , bookings_source_src_28000.is_instant AS booking__is_instant , bookings_source_src_28000.guest_id AS bookers - FROM ***************************.mf_time_spine subq_17 + FROM ***************************.mf_time_spine subq_13 INNER JOIN ***************************.fct_bookings bookings_source_src_28000 ON ( - DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_17.ds + DATE_TRUNC('day', bookings_source_src_28000.ds) <= subq_13.ds ) AND ( - DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_17.ds - INTERVAL 2 day + DATE_TRUNC('day', bookings_source_src_28000.ds) > subq_13.ds - INTERVAL 2 day ) - ) subq_19 + ) subq_14 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_19.listing = listings_latest_src_28000.listing_id -) subq_24 + subq_14.listing = listings_latest_src_28000.listing_id +) subq_17 WHERE booking__is_instant GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql index fa11e9c676..ded94f79fa 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0.sql @@ -1,359 +1,36 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_12.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value + subq_9.metric_time__day + , CAST(subq_9.average_booking_value AS DOUBLE) / CAST(NULLIF(subq_9.max_booking_value, 0) AS DOUBLE) AS instant_booking_fraction_of_max_value FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.average_booking_value) AS average_booking_value - , MAX(subq_11.max_booking_value) AS max_booking_value + COALESCE(subq_4.metric_time__day, subq_8.metric_time__day) AS metric_time__day + , MAX(subq_4.average_booking_value) AS average_booking_value + , MAX(subq_8.max_booking_value) AS max_booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.average_booking_value + subq_3.metric_time__day + , subq_3.average_booking_value FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , AVG(subq_4.average_booking_value) AS average_booking_value + subq_2.metric_time__day + , AVG(subq_2.average_booking_value) AS average_booking_value FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.average_booking_value - FROM ( - -- Constrain Output with WHERE - SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.average_booking_value - FROM ( - -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] - SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.average_booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - WHERE booking__is_instant - ) subq_3 - ) subq_4 - GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_10.metric_time__day - , subq_10.max_booking_value - FROM ( - -- Aggregate Measures - SELECT - subq_9.metric_time__day - , MAX(subq_9.max_booking_value) AS max_booking_value - FROM ( - -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] - SELECT - subq_8.metric_time__day - , subq_8.max_booking_value + subq_1.metric_time__day + , subq_1.average_booking_value FROM ( -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['average_booking_value', 'booking__is_instant', 'metric_time__day'] 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.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.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.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_0.ds__day AS metric_time__day + , subq_0.booking__is_instant + , subq_0.average_booking_value FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -446,15 +123,130 @@ 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_7 - ) subq_8 - ) subq_9 + ) subq_0 + ) subq_1 + WHERE booking__is_instant + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ) subq_4 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_7.metric_time__day + , subq_7.max_booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_6.metric_time__day + , MAX(subq_6.max_booking_value) AS max_booking_value + FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['max_booking_value', 'metric_time__day'] + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.max_booking_value + 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_5 + ) subq_6 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_6.metric_time__day + ) subq_7 + ) subq_8 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_4.metric_time__day = subq_8.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_4.metric_time__day, subq_8.metric_time__day) +) subq_9 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql index 6f2a446f78..95d54e79e4 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_different_filters_on_same_measure_source_categorical_dimension__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.average_booking_value) AS average_booking_value - , MAX(subq_24.max_booking_value) AS max_booking_value + COALESCE(subq_14.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_14.average_booking_value) AS average_booking_value + , MAX(subq_18.max_booking_value) AS max_booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] @@ -25,11 +25,11 @@ FROM ( , is_instant AS booking__is_instant , booking_value AS average_booking_value FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + ) subq_11 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_14 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +42,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_18 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_14.metric_time__day = subq_18.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_14.metric_time__day, subq_18.metric_time__day) +) subq_19 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 620302ced3..c04ab8cde5 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 @@ -1,948 +1,574 @@ -- Compute Metrics via Expressions SELECT - subq_33.metric_time__day - , subq_33.listing__country_latest + subq_25.metric_time__day + , subq_25.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_14.metric_time__day, subq_32.metric_time__day) AS metric_time__day - , COALESCE(subq_14.listing__country_latest, subq_32.listing__country_latest) AS listing__country_latest - , COALESCE(MAX(subq_14.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , COALESCE(MAX(subq_32.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_10.metric_time__day, subq_24.metric_time__day) AS metric_time__day + , COALESCE(subq_10.listing__country_latest, subq_24.listing__country_latest) AS listing__country_latest + , COALESCE(MAX(subq_10.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , COALESCE(MAX(subq_24.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day - , subq_13.listing__country_latest - , COALESCE(subq_13.bookings, 0) AS bookings_fill_nulls_with_0 + subq_9.metric_time__day + , subq_9.listing__country_latest + , COALESCE(subq_9.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_11.metric_time__day AS metric_time__day - , subq_10.listing__country_latest AS listing__country_latest - , subq_10.bookings AS bookings + subq_7.metric_time__day AS metric_time__day + , subq_6.listing__country_latest AS listing__country_latest + , subq_6.bookings AS bookings FROM ( -- Time Spine SELECT - subq_12.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_12 - ) subq_11 + subq_8.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_8 + ) subq_7 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , subq_9.listing__country_latest - , SUM(subq_9.bookings) AS bookings + subq_5.metric_time__day + , subq_5.listing__country_latest + , SUM(subq_5.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.listing__country_latest - , subq_8.bookings + subq_4.metric_time__day + , subq_4.listing__country_latest + , subq_4.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , subq_7.listing__country_latest - , subq_7.bookings + subq_1.metric_time__day AS metric_time__day + , subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_6.metric_time__day - , subq_6.booking__is_instant - , subq_6.listing__country_latest - , subq_6.bookings + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.country_latest AS listing__country_latest - , subq_2.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] - SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.booking__is_instant - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] - SELECT - subq_4.listing - , subq_4.country_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE booking__is_instant - ) subq_8 - ) subq_9 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_2.listing + , subq_2.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE booking__is_instant + ) subq_5 GROUP BY - subq_9.metric_time__day - , subq_9.listing__country_latest - ) subq_10 + subq_5.metric_time__day + , subq_5.listing__country_latest + ) subq_6 ON - subq_11.metric_time__day = subq_10.metric_time__day - ) subq_13 - ) subq_14 + subq_7.metric_time__day = subq_6.metric_time__day + ) subq_9 + ) subq_10 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_31.metric_time__day - , subq_31.listing__country_latest - , COALESCE(subq_31.bookings, 0) AS bookings_2_weeks_ago + subq_23.metric_time__day + , subq_23.listing__country_latest + , COALESCE(subq_23.bookings, 0) AS bookings_2_weeks_ago FROM ( -- Join to Time Spine Dataset SELECT - subq_29.metric_time__day AS metric_time__day - , subq_28.listing__country_latest AS listing__country_latest - , subq_28.bookings AS bookings + subq_21.metric_time__day AS metric_time__day + , subq_20.listing__country_latest AS listing__country_latest + , subq_20.bookings AS bookings FROM ( -- Time Spine SELECT - subq_30.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_30 - ) subq_29 + subq_22.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_22 + ) subq_21 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_27.metric_time__day - , subq_27.listing__country_latest - , SUM(subq_27.bookings) AS bookings + subq_19.metric_time__day + , subq_19.listing__country_latest + , SUM(subq_19.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_26.metric_time__day - , subq_26.listing__country_latest - , subq_26.bookings + subq_18.metric_time__day + , subq_18.listing__country_latest + , subq_18.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_25.metric_time__day - , subq_25.booking__is_instant - , subq_25.listing__country_latest - , subq_25.bookings + subq_15.metric_time__day AS metric_time__day + , subq_15.booking__is_instant AS booking__is_instant + , subq_15.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_24.metric_time__day - , subq_24.booking__is_instant - , subq_24.listing__country_latest - , subq_24.bookings + subq_13.metric_time__day AS metric_time__day + , subq_12.listing AS listing + , subq_12.booking__is_instant AS booking__is_instant + , subq_12.bookings AS bookings FROM ( - -- Join Standard Outputs + -- Time Spine SELECT - subq_20.metric_time__day AS metric_time__day - , subq_20.listing AS listing - , subq_20.booking__is_instant AS booking__is_instant - , subq_23.country_latest AS listing__country_latest - , subq_20.bookings AS bookings + subq_14.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_14 + ) subq_13 + INNER JOIN ( + -- Metric Time Dimension 'ds' + 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_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.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.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 ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] - SELECT - subq_19.metric_time__day - , subq_19.listing - , subq_19.booking__is_instant - , subq_19.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_17.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_17.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_17.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_17.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_17.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_17.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_17.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_17.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_17.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_17.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_17.metric_time__day) AS metric_time__extract_doy - , subq_16.ds__day AS ds__day - , subq_16.ds__week AS ds__week - , subq_16.ds__month AS ds__month - , subq_16.ds__quarter AS ds__quarter - , subq_16.ds__year AS ds__year - , subq_16.ds__extract_year AS ds__extract_year - , subq_16.ds__extract_quarter AS ds__extract_quarter - , subq_16.ds__extract_month AS ds__extract_month - , subq_16.ds__extract_day AS ds__extract_day - , subq_16.ds__extract_dow AS ds__extract_dow - , subq_16.ds__extract_doy AS ds__extract_doy - , subq_16.ds_partitioned__day AS ds_partitioned__day - , subq_16.ds_partitioned__week AS ds_partitioned__week - , subq_16.ds_partitioned__month AS ds_partitioned__month - , subq_16.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_16.ds_partitioned__year AS ds_partitioned__year - , subq_16.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_16.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_16.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_16.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_16.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_16.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_16.paid_at__day AS paid_at__day - , subq_16.paid_at__week AS paid_at__week - , subq_16.paid_at__month AS paid_at__month - , subq_16.paid_at__quarter AS paid_at__quarter - , subq_16.paid_at__year AS paid_at__year - , subq_16.paid_at__extract_year AS paid_at__extract_year - , subq_16.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_16.paid_at__extract_month AS paid_at__extract_month - , subq_16.paid_at__extract_day AS paid_at__extract_day - , subq_16.paid_at__extract_dow AS paid_at__extract_dow - , subq_16.paid_at__extract_doy AS paid_at__extract_doy - , subq_16.booking__ds__day AS booking__ds__day - , subq_16.booking__ds__week AS booking__ds__week - , subq_16.booking__ds__month AS booking__ds__month - , subq_16.booking__ds__quarter AS booking__ds__quarter - , subq_16.booking__ds__year AS booking__ds__year - , subq_16.booking__ds__extract_year AS booking__ds__extract_year - , subq_16.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_16.booking__ds__extract_month AS booking__ds__extract_month - , subq_16.booking__ds__extract_day AS booking__ds__extract_day - , subq_16.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_16.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_16.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_16.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_16.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_16.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_16.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_16.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_16.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_16.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_16.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_16.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_16.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_16.booking__paid_at__day AS booking__paid_at__day - , subq_16.booking__paid_at__week AS booking__paid_at__week - , subq_16.booking__paid_at__month AS booking__paid_at__month - , subq_16.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_16.booking__paid_at__year AS booking__paid_at__year - , subq_16.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_16.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_16.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_16.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_16.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_16.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_16.listing AS listing - , subq_16.guest AS guest - , subq_16.host AS host - , subq_16.booking__listing AS booking__listing - , subq_16.booking__guest AS booking__guest - , subq_16.booking__host AS booking__host - , subq_16.is_instant AS is_instant - , subq_16.booking__is_instant AS booking__is_instant - , subq_16.bookings AS bookings - , subq_16.instant_bookings AS instant_bookings - , subq_16.booking_value AS booking_value - , subq_16.max_booking_value AS max_booking_value - , subq_16.min_booking_value AS min_booking_value - , subq_16.bookers AS bookers - , subq_16.average_booking_value AS average_booking_value - , subq_16.referred_bookings AS referred_bookings - , subq_16.median_booking_value AS median_booking_value - , subq_16.booking_value_p99 AS booking_value_p99 - , subq_16.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_16.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_16.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 - FROM ( - -- Time Spine - SELECT - subq_18.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_18 - ) subq_17 - INNER JOIN ( - -- 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.ds_partitioned__day - , subq_15.ds_partitioned__week - , subq_15.ds_partitioned__month - , subq_15.ds_partitioned__quarter - , subq_15.ds_partitioned__year - , subq_15.ds_partitioned__extract_year - , subq_15.ds_partitioned__extract_quarter - , subq_15.ds_partitioned__extract_month - , subq_15.ds_partitioned__extract_day - , subq_15.ds_partitioned__extract_dow - , subq_15.ds_partitioned__extract_doy - , subq_15.paid_at__day - , subq_15.paid_at__week - , subq_15.paid_at__month - , subq_15.paid_at__quarter - , subq_15.paid_at__year - , subq_15.paid_at__extract_year - , subq_15.paid_at__extract_quarter - , subq_15.paid_at__extract_month - , subq_15.paid_at__extract_day - , subq_15.paid_at__extract_dow - , subq_15.paid_at__extract_doy - , subq_15.booking__ds__day - , subq_15.booking__ds__week - , subq_15.booking__ds__month - , subq_15.booking__ds__quarter - , subq_15.booking__ds__year - , subq_15.booking__ds__extract_year - , subq_15.booking__ds__extract_quarter - , subq_15.booking__ds__extract_month - , subq_15.booking__ds__extract_day - , subq_15.booking__ds__extract_dow - , subq_15.booking__ds__extract_doy - , subq_15.booking__ds_partitioned__day - , subq_15.booking__ds_partitioned__week - , subq_15.booking__ds_partitioned__month - , subq_15.booking__ds_partitioned__quarter - , subq_15.booking__ds_partitioned__year - , subq_15.booking__ds_partitioned__extract_year - , subq_15.booking__ds_partitioned__extract_quarter - , subq_15.booking__ds_partitioned__extract_month - , subq_15.booking__ds_partitioned__extract_day - , subq_15.booking__ds_partitioned__extract_dow - , subq_15.booking__ds_partitioned__extract_doy - , subq_15.booking__paid_at__day - , subq_15.booking__paid_at__week - , subq_15.booking__paid_at__month - , subq_15.booking__paid_at__quarter - , subq_15.booking__paid_at__year - , subq_15.booking__paid_at__extract_year - , subq_15.booking__paid_at__extract_quarter - , subq_15.booking__paid_at__extract_month - , subq_15.booking__paid_at__extract_day - , subq_15.booking__paid_at__extract_dow - , subq_15.booking__paid_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.guest - , subq_15.host - , subq_15.booking__listing - , subq_15.booking__guest - , subq_15.booking__host - , subq_15.is_instant - , subq_15.booking__is_instant - , subq_15.bookings - , subq_15.instant_bookings - , subq_15.booking_value - , subq_15.max_booking_value - , subq_15.min_booking_value - , subq_15.bookers - , subq_15.average_booking_value - , subq_15.referred_bookings - , subq_15.median_booking_value - , subq_15.booking_value_p99 - , subq_15.discrete_booking_value_p99 - , subq_15.approximate_continuous_booking_value_p99 - , subq_15.approximate_discrete_booking_value_p99 - 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_15 - ) subq_16 - ON - subq_17.metric_time__day - INTERVAL 14 day = subq_16.metric_time__day - ) subq_19 - ) subq_20 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_22.listing - , subq_22.country_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - 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.created_at__day - , subq_21.created_at__week - , subq_21.created_at__month - , subq_21.created_at__quarter - , subq_21.created_at__year - , subq_21.created_at__extract_year - , subq_21.created_at__extract_quarter - , subq_21.created_at__extract_month - , subq_21.created_at__extract_day - , subq_21.created_at__extract_dow - , subq_21.created_at__extract_doy - , subq_21.listing__ds__day - , subq_21.listing__ds__week - , subq_21.listing__ds__month - , subq_21.listing__ds__quarter - , subq_21.listing__ds__year - , subq_21.listing__ds__extract_year - , subq_21.listing__ds__extract_quarter - , subq_21.listing__ds__extract_month - , subq_21.listing__ds__extract_day - , subq_21.listing__ds__extract_dow - , subq_21.listing__ds__extract_doy - , subq_21.listing__created_at__day - , subq_21.listing__created_at__week - , subq_21.listing__created_at__month - , subq_21.listing__created_at__quarter - , subq_21.listing__created_at__year - , subq_21.listing__created_at__extract_year - , subq_21.listing__created_at__extract_quarter - , subq_21.listing__created_at__extract_month - , subq_21.listing__created_at__extract_day - , subq_21.listing__created_at__extract_dow - , subq_21.listing__created_at__extract_doy - , subq_21.ds__day AS metric_time__day - , subq_21.ds__week AS metric_time__week - , subq_21.ds__month AS metric_time__month - , subq_21.ds__quarter AS metric_time__quarter - , subq_21.ds__year AS metric_time__year - , subq_21.ds__extract_year AS metric_time__extract_year - , subq_21.ds__extract_quarter AS metric_time__extract_quarter - , subq_21.ds__extract_month AS metric_time__extract_month - , subq_21.ds__extract_day AS metric_time__extract_day - , subq_21.ds__extract_dow AS metric_time__extract_dow - , subq_21.ds__extract_doy AS metric_time__extract_doy - , subq_21.listing - , subq_21.user - , subq_21.listing__user - , subq_21.country_latest - , subq_21.is_lux_latest - , subq_21.capacity_latest - , subq_21.listing__country_latest - , subq_21.listing__is_lux_latest - , subq_21.listing__capacity_latest - , subq_21.listings - , subq_21.largest_listing - , subq_21.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_21 - ) subq_22 - ) subq_23 - ON - subq_20.listing = subq_23.listing - ) subq_24 - ) subq_25 - WHERE booking__is_instant - ) subq_26 - ) subq_27 + 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_11 + ) subq_12 + ON + subq_13.metric_time__day - INTERVAL 14 day = subq_12.metric_time__day + ) subq_15 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_16.listing + , subq_16.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_16 + ) subq_17 + ON + subq_15.listing = subq_17.listing + ) subq_18 + WHERE booking__is_instant + ) subq_19 GROUP BY - subq_27.metric_time__day - , subq_27.listing__country_latest - ) subq_28 + subq_19.metric_time__day + , subq_19.listing__country_latest + ) subq_20 ON - subq_29.metric_time__day = subq_28.metric_time__day - ) subq_31 - ) subq_32 + subq_21.metric_time__day = subq_20.metric_time__day + ) subq_23 + ) subq_24 ON ( - subq_14.listing__country_latest = subq_32.listing__country_latest + subq_10.listing__country_latest = subq_24.listing__country_latest ) AND ( - subq_14.metric_time__day = subq_32.metric_time__day + subq_10.metric_time__day = subq_24.metric_time__day ) GROUP BY - COALESCE(subq_14.metric_time__day, subq_32.metric_time__day) - , COALESCE(subq_14.listing__country_latest, subq_32.listing__country_latest) -) subq_33 + COALESCE(subq_10.metric_time__day, subq_24.metric_time__day) + , COALESCE(subq_10.listing__country_latest, subq_24.listing__country_latest) +) subq_25 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 5197e5dca7..b29cefedc4 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 @@ -6,10 +6,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_48.metric_time__day, subq_66.metric_time__day) AS metric_time__day - , COALESCE(subq_48.listing__country_latest, subq_66.listing__country_latest) AS listing__country_latest - , COALESCE(MAX(subq_48.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 - , COALESCE(MAX(subq_66.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago + COALESCE(subq_36.metric_time__day, subq_50.metric_time__day) AS metric_time__day + , COALESCE(subq_36.listing__country_latest, subq_50.listing__country_latest) AS listing__country_latest + , COALESCE(MAX(subq_36.bookings_fill_nulls_with_0), 0) AS bookings_fill_nulls_with_0 + , COALESCE(MAX(subq_50.bookings_2_weeks_ago), 0) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT @@ -19,10 +19,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_46.ds AS metric_time__day - , subq_44.listing__country_latest AS listing__country_latest - , subq_44.bookings AS bookings - FROM ***************************.mf_time_spine subq_46 + subq_34.ds AS metric_time__day + , subq_32.listing__country_latest AS listing__country_latest + , subq_32.bookings AS bookings + FROM ***************************.mf_time_spine subq_34 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -35,10 +35,9 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_36.metric_time__day AS metric_time__day - , subq_36.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.country AS listing__country_latest - , subq_36.bookings AS bookings + subq_27.metric_time__day AS metric_time__day + , subq_27.booking__is_instant AS booking__is_instant + , subq_27.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -49,21 +48,21 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_36 + ) subq_27 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_36.listing = listings_latest_src_28000.listing_id - ) subq_41 + subq_27.listing = listings_latest_src_28000.listing_id + ) subq_30 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_44 + ) subq_32 ON - subq_46.ds = subq_44.metric_time__day - ) subq_47 - ) subq_48 + subq_34.ds = subq_32.metric_time__day + ) subq_35 + ) subq_36 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT @@ -73,10 +72,10 @@ FROM ( FROM ( -- Join to Time Spine Dataset SELECT - subq_64.ds AS metric_time__day - , subq_62.listing__country_latest AS listing__country_latest - , subq_62.bookings AS bookings - FROM ***************************.mf_time_spine subq_64 + subq_48.ds AS metric_time__day + , subq_46.listing__country_latest AS listing__country_latest + , subq_46.bookings AS bookings + FROM ***************************.mf_time_spine subq_48 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -89,19 +88,18 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_54.metric_time__day AS metric_time__day - , subq_54.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.country AS listing__country_latest - , subq_54.bookings AS bookings + subq_41.metric_time__day AS metric_time__day + , subq_41.booking__is_instant AS booking__is_instant + , subq_41.bookings AS bookings FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_52.ds AS metric_time__day - , subq_50.listing AS listing - , subq_50.booking__is_instant AS booking__is_instant - , subq_50.bookings AS bookings - FROM ***************************.mf_time_spine subq_52 + subq_40.ds AS metric_time__day + , subq_38.listing AS listing + , subq_38.booking__is_instant AS booking__is_instant + , subq_38.bookings AS bookings + FROM ***************************.mf_time_spine subq_40 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -111,31 +109,31 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_50 + ) subq_38 ON - subq_52.ds - INTERVAL 14 day = subq_50.metric_time__day - ) subq_54 + subq_40.ds - INTERVAL 14 day = subq_38.metric_time__day + ) subq_41 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_54.listing = listings_latest_src_28000.listing_id - ) subq_59 + subq_41.listing = listings_latest_src_28000.listing_id + ) subq_44 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_62 + ) subq_46 ON - subq_64.ds = subq_62.metric_time__day - ) subq_65 - ) subq_66 + subq_48.ds = subq_46.metric_time__day + ) subq_49 + ) subq_50 ON ( - subq_48.listing__country_latest = subq_66.listing__country_latest + subq_36.listing__country_latest = subq_50.listing__country_latest ) AND ( - subq_48.metric_time__day = subq_66.metric_time__day + subq_36.metric_time__day = subq_50.metric_time__day ) GROUP BY - COALESCE(subq_48.metric_time__day, subq_66.metric_time__day) - , COALESCE(subq_48.listing__country_latest, subq_66.listing__country_latest) -) subq_67 + COALESCE(subq_36.metric_time__day, subq_50.metric_time__day) + , COALESCE(subq_36.listing__country_latest, subq_50.listing__country_latest) +) subq_51 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_metric_time_filter_with_two_targets__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_metric_time_filter_with_two_targets__plan0.sql index 4107fcf148..cbc5baa52f 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_metric_time_filter_with_two_targets__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_metric_time_filter_with_two_targets__plan0.sql @@ -1,383 +1,198 @@ -- Compute Metrics via Expressions SELECT - subq_10.listing__country_latest - , subq_10.bookings + subq_6.listing__country_latest + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_9.listing__country_latest - , SUM(subq_9.bookings) AS bookings + subq_5.listing__country_latest + , SUM(subq_5.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest'] SELECT - subq_8.listing__country_latest - , subq_8.bookings + subq_4.listing__country_latest + , subq_4.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.listing__country_latest - , subq_7.bookings + subq_1.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] SELECT - subq_6.metric_time__day - , subq_6.listing__country_latest - , subq_6.bookings + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_5.country_latest AS listing__country_latest - , subq_2.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] - SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] - SELECT - subq_4.listing - , subq_4.country_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE metric_time__day = '2024-01-01' - ) subq_8 - ) subq_9 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_2.listing + , subq_2.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE metric_time__day = '2024-01-01' + ) subq_5 GROUP BY - subq_9.listing__country_latest -) subq_10 + subq_5.listing__country_latest +) subq_6 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_metric_time_filter_with_two_targets__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_metric_time_filter_with_two_targets__plan0_optimized.sql index b5d0efe756..dd58001fde 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_metric_time_filter_with_two_targets__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_metric_time_filter_with_two_targets__plan0_optimized.sql @@ -9,9 +9,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_13.metric_time__day AS metric_time__day - , listings_latest_src_28000.country AS listing__country_latest - , subq_13.bookings AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_8.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -21,12 +20,12 @@ FROM ( , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_8 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_13.listing = listings_latest_src_28000.listing_id -) subq_18 + subq_8.listing = listings_latest_src_28000.listing_id +) subq_11 WHERE metric_time__day = '2024-01-01' GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0.sql index 70f27e867b..fb834a17a8 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0.sql @@ -1,222 +1,108 @@ -- Compute Metrics via Expressions SELECT - subq_9.user__home_state_latest - , subq_9.listings + subq_5.user__home_state_latest + , subq_5.listings FROM ( -- Aggregate Measures SELECT - subq_8.user__home_state_latest - , SUM(subq_8.listings) AS listings + subq_4.user__home_state_latest + , SUM(subq_4.listings) AS listings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listings', 'user__home_state_latest'] SELECT - subq_7.user__home_state_latest - , subq_7.listings + subq_3.user__home_state_latest + , subq_3.listings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] SELECT - subq_6.listing__is_lux_latest - , subq_6.listing__capacity_latest - , subq_6.user__home_state_latest - , subq_6.listings + subq_1.listing__is_lux_latest AS listing__is_lux_latest + , subq_1.listing__capacity_latest AS listing__capacity_latest + , subq_1.listings AS listings FROM ( - -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] SELECT - subq_5.listing__is_lux_latest - , subq_5.listing__capacity_latest - , subq_5.user__home_state_latest - , subq_5.listings + subq_0.user + , subq_0.listing__is_lux_latest + , subq_0.listing__capacity_latest + , subq_0.listings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_2.user AS user - , subq_2.listing__is_lux_latest AS listing__is_lux_latest - , subq_2.listing__capacity_latest AS listing__capacity_latest - , subq_4.home_state_latest AS user__home_state_latest - , subq_2.listings AS listings - FROM ( - -- Pass Only Elements: ['listings', 'listing__is_lux_latest', 'listing__capacity_latest', 'user'] - SELECT - subq_1.user - , subq_1.listing__is_lux_latest - , subq_1.listing__capacity_latest - , subq_1.listings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['home_state_latest', 'user'] - SELECT - subq_3.user - , subq_3.home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_28000.ds) AS ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS ds_latest__extract_doy - , users_latest_src_28000.home_state_latest - , DATE_TRUNC('day', users_latest_src_28000.ds) AS user__ds_latest__day - , DATE_TRUNC('week', users_latest_src_28000.ds) AS user__ds_latest__week - , DATE_TRUNC('month', users_latest_src_28000.ds) AS user__ds_latest__month - , DATE_TRUNC('quarter', users_latest_src_28000.ds) AS user__ds_latest__quarter - , DATE_TRUNC('year', users_latest_src_28000.ds) AS user__ds_latest__year - , EXTRACT(year FROM users_latest_src_28000.ds) AS user__ds_latest__extract_year - , EXTRACT(quarter FROM users_latest_src_28000.ds) AS user__ds_latest__extract_quarter - , EXTRACT(month FROM users_latest_src_28000.ds) AS user__ds_latest__extract_month - , EXTRACT(day FROM users_latest_src_28000.ds) AS user__ds_latest__extract_day - , EXTRACT(isodow FROM users_latest_src_28000.ds) AS user__ds_latest__extract_dow - , EXTRACT(doy FROM users_latest_src_28000.ds) AS user__ds_latest__extract_doy - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , users_latest_src_28000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_28000 - ) subq_3 - ) subq_4 - ON - subq_2.user = subq_4.user - ) subq_5 - ) subq_6 - WHERE listing__is_lux_latest OR listing__capacity_latest > 4 - ) subq_7 - ) subq_8 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: ['home_state_latest', 'user'] + SELECT + users_latest_src_28000.home_state_latest + , users_latest_src_28000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_28000 + ) subq_2 + ON + subq_1.user = subq_2.user + ) subq_3 + WHERE listing__is_lux_latest OR listing__capacity_latest > 4 + ) subq_4 GROUP BY - subq_8.user__home_state_latest -) subq_9 + subq_4.user__home_state_latest +) subq_5 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql index 660d3f8e29..0b9a4026b8 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_multiple_categorical_dimension_pushdown__plan0_optimized.sql @@ -9,10 +9,9 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['listings', 'user__home_state_latest', 'listing__is_lux_latest', 'listing__capacity_latest'] SELECT - subq_12.listing__is_lux_latest AS listing__is_lux_latest - , subq_12.listing__capacity_latest AS listing__capacity_latest - , users_latest_src_28000.home_state_latest AS user__home_state_latest - , subq_12.listings AS listings + subq_7.listing__is_lux_latest AS listing__is_lux_latest + , subq_7.listing__capacity_latest AS listing__capacity_latest + , subq_7.listings AS listings FROM ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -23,12 +22,12 @@ FROM ( , capacity AS listing__capacity_latest , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 - ) subq_12 + ) subq_7 LEFT OUTER JOIN ***************************.dim_users_latest users_latest_src_28000 ON - subq_12.user = users_latest_src_28000.user_id -) subq_16 + subq_7.user = users_latest_src_28000.user_id +) subq_9 WHERE listing__is_lux_latest OR listing__capacity_latest > 4 GROUP BY user__home_state_latest 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 2bbf738849..aea9387612 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 @@ -1,918 +1,544 @@ -- Compute Metrics via Expressions SELECT - subq_27.metric_time__day - , subq_27.listing__country_latest + subq_19.metric_time__day + , subq_19.listing__country_latest , bookings - bookings_2_weeks_ago AS bookings_growth_2_weeks FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_11.metric_time__day, subq_26.metric_time__day) AS metric_time__day - , COALESCE(subq_11.listing__country_latest, subq_26.listing__country_latest) AS listing__country_latest - , MAX(subq_11.bookings) AS bookings - , MAX(subq_26.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_7.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , COALESCE(subq_7.listing__country_latest, subq_18.listing__country_latest) AS listing__country_latest + , MAX(subq_7.bookings) AS bookings + , MAX(subq_18.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.listing__country_latest - , subq_10.bookings + subq_6.metric_time__day + , subq_6.listing__country_latest + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , subq_9.listing__country_latest - , SUM(subq_9.bookings) AS bookings + subq_5.metric_time__day + , subq_5.listing__country_latest + , SUM(subq_5.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.listing__country_latest - , subq_8.bookings + subq_4.metric_time__day + , subq_4.listing__country_latest + , subq_4.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.booking__is_instant - , subq_7.listing__country_latest - , subq_7.bookings + subq_1.metric_time__day AS metric_time__day + , subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_6.metric_time__day - , subq_6.booking__is_instant - , subq_6.listing__country_latest - , subq_6.bookings + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.country_latest AS listing__country_latest - , subq_2.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] - SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.booking__is_instant - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] - SELECT - subq_4.listing - , subq_4.country_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE booking__is_instant - ) subq_8 - ) subq_9 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_2.listing + , subq_2.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE booking__is_instant + ) subq_5 GROUP BY - subq_9.metric_time__day - , subq_9.listing__country_latest - ) subq_10 - ) subq_11 + subq_5.metric_time__day + , subq_5.listing__country_latest + ) subq_6 + ) subq_7 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_25.metric_time__day - , subq_25.listing__country_latest - , subq_25.bookings AS bookings_2_weeks_ago + subq_17.metric_time__day + , subq_17.listing__country_latest + , subq_17.bookings AS bookings_2_weeks_ago FROM ( -- Aggregate Measures SELECT - subq_24.metric_time__day - , subq_24.listing__country_latest - , SUM(subq_24.bookings) AS bookings + subq_16.metric_time__day + , subq_16.listing__country_latest + , SUM(subq_16.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] SELECT - subq_23.metric_time__day - , subq_23.listing__country_latest - , subq_23.bookings + subq_15.metric_time__day + , subq_15.listing__country_latest + , subq_15.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_22.metric_time__day - , subq_22.booking__is_instant - , subq_22.listing__country_latest - , subq_22.bookings + subq_12.metric_time__day AS metric_time__day + , subq_12.booking__is_instant AS booking__is_instant + , subq_12.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] + -- Join to Time Spine Dataset + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_21.metric_time__day - , subq_21.booking__is_instant - , subq_21.listing__country_latest - , subq_21.bookings + subq_10.metric_time__day AS metric_time__day + , subq_9.listing AS listing + , subq_9.booking__is_instant AS booking__is_instant + , subq_9.bookings AS bookings FROM ( - -- Join Standard Outputs + -- Time Spine SELECT - subq_17.metric_time__day AS metric_time__day - , subq_17.listing AS listing - , subq_17.booking__is_instant AS booking__is_instant - , subq_20.country_latest AS listing__country_latest - , subq_17.bookings AS bookings + subq_11.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_11 + ) subq_10 + 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 FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] - SELECT - subq_16.metric_time__day - , subq_16.listing - , subq_16.booking__is_instant - , subq_16.bookings - FROM ( - -- Join to Time Spine Dataset - SELECT - subq_14.metric_time__day AS metric_time__day - , DATE_TRUNC('week', subq_14.metric_time__day) AS metric_time__week - , DATE_TRUNC('month', subq_14.metric_time__day) AS metric_time__month - , DATE_TRUNC('quarter', subq_14.metric_time__day) AS metric_time__quarter - , DATE_TRUNC('year', subq_14.metric_time__day) AS metric_time__year - , EXTRACT(year FROM subq_14.metric_time__day) AS metric_time__extract_year - , EXTRACT(quarter FROM subq_14.metric_time__day) AS metric_time__extract_quarter - , EXTRACT(month FROM subq_14.metric_time__day) AS metric_time__extract_month - , EXTRACT(day FROM subq_14.metric_time__day) AS metric_time__extract_day - , EXTRACT(isodow FROM subq_14.metric_time__day) AS metric_time__extract_dow - , EXTRACT(doy FROM subq_14.metric_time__day) AS metric_time__extract_doy - , subq_13.ds__day AS ds__day - , subq_13.ds__week AS ds__week - , subq_13.ds__month AS ds__month - , subq_13.ds__quarter AS ds__quarter - , subq_13.ds__year AS ds__year - , subq_13.ds__extract_year AS ds__extract_year - , subq_13.ds__extract_quarter AS ds__extract_quarter - , subq_13.ds__extract_month AS ds__extract_month - , subq_13.ds__extract_day AS ds__extract_day - , subq_13.ds__extract_dow AS ds__extract_dow - , subq_13.ds__extract_doy AS ds__extract_doy - , subq_13.ds_partitioned__day AS ds_partitioned__day - , subq_13.ds_partitioned__week AS ds_partitioned__week - , subq_13.ds_partitioned__month AS ds_partitioned__month - , subq_13.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_13.ds_partitioned__year AS ds_partitioned__year - , subq_13.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_13.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_13.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_13.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_13.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_13.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_13.paid_at__day AS paid_at__day - , subq_13.paid_at__week AS paid_at__week - , subq_13.paid_at__month AS paid_at__month - , subq_13.paid_at__quarter AS paid_at__quarter - , subq_13.paid_at__year AS paid_at__year - , subq_13.paid_at__extract_year AS paid_at__extract_year - , subq_13.paid_at__extract_quarter AS paid_at__extract_quarter - , subq_13.paid_at__extract_month AS paid_at__extract_month - , subq_13.paid_at__extract_day AS paid_at__extract_day - , subq_13.paid_at__extract_dow AS paid_at__extract_dow - , subq_13.paid_at__extract_doy AS paid_at__extract_doy - , subq_13.booking__ds__day AS booking__ds__day - , subq_13.booking__ds__week AS booking__ds__week - , subq_13.booking__ds__month AS booking__ds__month - , subq_13.booking__ds__quarter AS booking__ds__quarter - , subq_13.booking__ds__year AS booking__ds__year - , subq_13.booking__ds__extract_year AS booking__ds__extract_year - , subq_13.booking__ds__extract_quarter AS booking__ds__extract_quarter - , subq_13.booking__ds__extract_month AS booking__ds__extract_month - , subq_13.booking__ds__extract_day AS booking__ds__extract_day - , subq_13.booking__ds__extract_dow AS booking__ds__extract_dow - , subq_13.booking__ds__extract_doy AS booking__ds__extract_doy - , subq_13.booking__ds_partitioned__day AS booking__ds_partitioned__day - , subq_13.booking__ds_partitioned__week AS booking__ds_partitioned__week - , subq_13.booking__ds_partitioned__month AS booking__ds_partitioned__month - , subq_13.booking__ds_partitioned__quarter AS booking__ds_partitioned__quarter - , subq_13.booking__ds_partitioned__year AS booking__ds_partitioned__year - , subq_13.booking__ds_partitioned__extract_year AS booking__ds_partitioned__extract_year - , subq_13.booking__ds_partitioned__extract_quarter AS booking__ds_partitioned__extract_quarter - , subq_13.booking__ds_partitioned__extract_month AS booking__ds_partitioned__extract_month - , subq_13.booking__ds_partitioned__extract_day AS booking__ds_partitioned__extract_day - , subq_13.booking__ds_partitioned__extract_dow AS booking__ds_partitioned__extract_dow - , subq_13.booking__ds_partitioned__extract_doy AS booking__ds_partitioned__extract_doy - , subq_13.booking__paid_at__day AS booking__paid_at__day - , subq_13.booking__paid_at__week AS booking__paid_at__week - , subq_13.booking__paid_at__month AS booking__paid_at__month - , subq_13.booking__paid_at__quarter AS booking__paid_at__quarter - , subq_13.booking__paid_at__year AS booking__paid_at__year - , subq_13.booking__paid_at__extract_year AS booking__paid_at__extract_year - , subq_13.booking__paid_at__extract_quarter AS booking__paid_at__extract_quarter - , subq_13.booking__paid_at__extract_month AS booking__paid_at__extract_month - , subq_13.booking__paid_at__extract_day AS booking__paid_at__extract_day - , subq_13.booking__paid_at__extract_dow AS booking__paid_at__extract_dow - , subq_13.booking__paid_at__extract_doy AS booking__paid_at__extract_doy - , subq_13.listing AS listing - , subq_13.guest AS guest - , subq_13.host AS host - , subq_13.booking__listing AS booking__listing - , subq_13.booking__guest AS booking__guest - , subq_13.booking__host AS booking__host - , subq_13.is_instant AS is_instant - , subq_13.booking__is_instant AS booking__is_instant - , subq_13.bookings AS bookings - , subq_13.instant_bookings AS instant_bookings - , subq_13.booking_value AS booking_value - , subq_13.max_booking_value AS max_booking_value - , subq_13.min_booking_value AS min_booking_value - , subq_13.bookers AS bookers - , subq_13.average_booking_value AS average_booking_value - , subq_13.referred_bookings AS referred_bookings - , subq_13.median_booking_value AS median_booking_value - , subq_13.booking_value_p99 AS booking_value_p99 - , subq_13.discrete_booking_value_p99 AS discrete_booking_value_p99 - , subq_13.approximate_continuous_booking_value_p99 AS approximate_continuous_booking_value_p99 - , subq_13.approximate_discrete_booking_value_p99 AS approximate_discrete_booking_value_p99 - FROM ( - -- Time Spine - SELECT - subq_15.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_15 - ) subq_14 - INNER JOIN ( - -- Metric Time Dimension 'ds' - SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 - 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_12 - ) subq_13 - ON - subq_14.metric_time__day - INTERVAL 14 day = subq_13.metric_time__day - ) subq_16 - ) subq_17 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_19.listing - , subq_19.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 - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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 - ON - subq_17.listing = subq_20.listing - ) subq_21 - ) subq_22 - WHERE booking__is_instant - ) subq_23 - ) subq_24 + 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_8 + ) subq_9 + ON + subq_10.metric_time__day - INTERVAL 14 day = subq_9.metric_time__day + ) subq_12 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_13.listing + , subq_13.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_13 + ) subq_14 + ON + subq_12.listing = subq_14.listing + ) subq_15 + WHERE booking__is_instant + ) subq_16 GROUP BY - subq_24.metric_time__day - , subq_24.listing__country_latest - ) subq_25 - ) subq_26 + subq_16.metric_time__day + , subq_16.listing__country_latest + ) subq_17 + ) subq_18 ON ( - subq_11.listing__country_latest = subq_26.listing__country_latest + subq_7.listing__country_latest = subq_18.listing__country_latest ) AND ( - subq_11.metric_time__day = subq_26.metric_time__day + subq_7.metric_time__day = subq_18.metric_time__day ) GROUP BY - COALESCE(subq_11.metric_time__day, subq_26.metric_time__day) - , COALESCE(subq_11.listing__country_latest, subq_26.listing__country_latest) -) subq_27 + COALESCE(subq_7.metric_time__day, subq_18.metric_time__day) + , COALESCE(subq_7.listing__country_latest, subq_18.listing__country_latest) +) subq_19 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 193672befc..563ebb996e 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 @@ -6,10 +6,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_39.metric_time__day, subq_54.metric_time__day) AS metric_time__day - , COALESCE(subq_39.listing__country_latest, subq_54.listing__country_latest) AS listing__country_latest - , MAX(subq_39.bookings) AS bookings - , MAX(subq_54.bookings_2_weeks_ago) AS bookings_2_weeks_ago + COALESCE(subq_27.metric_time__day, subq_38.metric_time__day) AS metric_time__day + , COALESCE(subq_27.listing__country_latest, subq_38.listing__country_latest) AS listing__country_latest + , MAX(subq_27.bookings) AS bookings + , MAX(subq_38.bookings_2_weeks_ago) AS bookings_2_weeks_ago FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -23,10 +23,9 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_30.metric_time__day AS metric_time__day - , subq_30.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.country AS listing__country_latest - , subq_30.bookings AS bookings + subq_21.metric_time__day AS metric_time__day + , subq_21.booking__is_instant AS booking__is_instant + , subq_21.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -37,17 +36,17 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_30 + ) subq_21 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_30.listing = listings_latest_src_28000.listing_id - ) subq_35 + subq_21.listing = listings_latest_src_28000.listing_id + ) subq_24 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_39 + ) subq_27 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest', 'metric_time__day'] @@ -61,19 +60,18 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'metric_time__day'] SELECT - subq_45.metric_time__day AS metric_time__day - , subq_45.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.country AS listing__country_latest - , subq_45.bookings AS bookings + subq_32.metric_time__day AS metric_time__day + , subq_32.booking__is_instant AS booking__is_instant + , subq_32.bookings AS bookings FROM ( -- Join to Time Spine Dataset -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day', 'listing'] SELECT - subq_43.ds AS metric_time__day - , subq_41.listing AS listing - , subq_41.booking__is_instant AS booking__is_instant - , subq_41.bookings AS bookings - FROM ***************************.mf_time_spine subq_43 + subq_31.ds AS metric_time__day + , subq_29.listing AS listing + , subq_29.booking__is_instant AS booking__is_instant + , subq_29.bookings AS bookings + FROM ***************************.mf_time_spine subq_31 INNER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -83,27 +81,27 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_41 + ) subq_29 ON - subq_43.ds - INTERVAL 14 day = subq_41.metric_time__day - ) subq_45 + subq_31.ds - INTERVAL 14 day = subq_29.metric_time__day + ) subq_32 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_45.listing = listings_latest_src_28000.listing_id - ) subq_50 + subq_32.listing = listings_latest_src_28000.listing_id + ) subq_35 WHERE booking__is_instant GROUP BY metric_time__day , listing__country_latest - ) subq_54 + ) subq_38 ON ( - subq_39.listing__country_latest = subq_54.listing__country_latest + subq_27.listing__country_latest = subq_38.listing__country_latest ) AND ( - subq_39.metric_time__day = subq_54.metric_time__day + subq_27.metric_time__day = subq_38.metric_time__day ) GROUP BY - COALESCE(subq_39.metric_time__day, subq_54.metric_time__day) - , COALESCE(subq_39.listing__country_latest, subq_54.listing__country_latest) -) subq_55 + COALESCE(subq_27.metric_time__day, subq_38.metric_time__day) + , COALESCE(subq_27.listing__country_latest, subq_38.listing__country_latest) +) subq_39 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0.sql index ae495323cd..8f926e4016 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0.sql @@ -1,1431 +1,755 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_11.listing__capacity_latest, subq_23.listing__capacity_latest, subq_49.listing__capacity_latest) AS listing__capacity_latest - , MAX(subq_11.bookings) AS bookings - , MAX(subq_23.views) AS views - , MAX(subq_49.bookings_per_view) AS bookings_per_view + COALESCE(subq_7.listing__capacity_latest, subq_15.listing__capacity_latest, subq_33.listing__capacity_latest) AS listing__capacity_latest + , MAX(subq_7.bookings) AS bookings + , MAX(subq_15.views) AS views + , MAX(subq_33.bookings_per_view) AS bookings_per_view FROM ( -- Compute Metrics via Expressions SELECT - subq_10.listing__capacity_latest - , subq_10.bookings + subq_6.listing__capacity_latest + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_9.listing__capacity_latest - , SUM(subq_9.bookings) AS bookings + subq_5.listing__capacity_latest + , SUM(subq_5.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__capacity_latest'] SELECT - subq_8.listing__capacity_latest - , subq_8.bookings + subq_4.listing__capacity_latest + , subq_4.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.listing__is_lux_latest - , subq_7.listing__capacity_latest - , subq_7.bookings + subq_1.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] SELECT - subq_6.metric_time__day - , subq_6.listing__is_lux_latest - , subq_6.listing__capacity_latest - , subq_6.bookings + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_5.capacity_latest AS listing__capacity_latest - , subq_2.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] - SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] - SELECT - subq_4.listing - , subq_4.is_lux_latest - , subq_4.capacity_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) - ) subq_8 - ) subq_9 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_2.listing + , subq_2.is_lux_latest + , subq_2.capacity_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) + ) subq_5 GROUP BY - subq_9.listing__capacity_latest - ) subq_10 -) subq_11 + subq_5.listing__capacity_latest + ) subq_6 +) subq_7 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.listing__capacity_latest - , subq_22.views + subq_14.listing__capacity_latest + , subq_14.views FROM ( -- Aggregate Measures SELECT - subq_21.listing__capacity_latest - , SUM(subq_21.views) AS views + subq_13.listing__capacity_latest + , SUM(subq_13.views) AS views FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['views', 'listing__capacity_latest'] SELECT - subq_20.listing__capacity_latest - , subq_20.views + subq_12.listing__capacity_latest + , subq_12.views FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['views', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_19.metric_time__day - , subq_19.listing__is_lux_latest - , subq_19.listing__capacity_latest - , subq_19.views + subq_9.metric_time__day AS metric_time__day + , subq_9.views AS views FROM ( - -- Pass Only Elements: ['views', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['views', 'metric_time__day', 'listing'] SELECT - subq_18.metric_time__day - , subq_18.listing__is_lux_latest - , subq_18.listing__capacity_latest - , subq_18.views + subq_8.ds__day AS metric_time__day + , subq_8.listing + , subq_8.views FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'views_source' SELECT - subq_14.metric_time__day AS metric_time__day - , subq_14.listing AS listing - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_17.capacity_latest AS listing__capacity_latest - , subq_14.views AS views - FROM ( - -- Pass Only Elements: ['views', 'metric_time__day', 'listing'] - SELECT - subq_13.metric_time__day - , subq_13.listing - , subq_13.views - FROM ( - -- Metric Time Dimension 'ds' - SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.view__ds__day - , subq_12.view__ds__week - , subq_12.view__ds__month - , subq_12.view__ds__quarter - , subq_12.view__ds__year - , subq_12.view__ds__extract_year - , subq_12.view__ds__extract_quarter - , subq_12.view__ds__extract_month - , subq_12.view__ds__extract_day - , subq_12.view__ds__extract_dow - , subq_12.view__ds__extract_doy - , subq_12.view__ds_partitioned__day - , subq_12.view__ds_partitioned__week - , subq_12.view__ds_partitioned__month - , subq_12.view__ds_partitioned__quarter - , subq_12.view__ds_partitioned__year - , subq_12.view__ds_partitioned__extract_year - , subq_12.view__ds_partitioned__extract_quarter - , subq_12.view__ds_partitioned__extract_month - , subq_12.view__ds_partitioned__extract_day - , subq_12.view__ds_partitioned__extract_dow - , subq_12.view__ds_partitioned__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.user - , subq_12.view__listing - , subq_12.view__user - , subq_12.views - FROM ( - -- Read Elements From Semantic Model 'views_source' - SELECT - 1 AS views - , DATE_TRUNC('day', views_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', views_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', views_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', views_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', views_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM views_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM views_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds) AS view__ds__day - , DATE_TRUNC('week', views_source_src_28000.ds) AS view__ds__week - , DATE_TRUNC('month', views_source_src_28000.ds) AS view__ds__month - , DATE_TRUNC('quarter', views_source_src_28000.ds) AS view__ds__quarter - , DATE_TRUNC('year', views_source_src_28000.ds) AS view__ds__year - , EXTRACT(year FROM views_source_src_28000.ds) AS view__ds__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds) AS view__ds__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds) AS view__ds__extract_month - , EXTRACT(day FROM views_source_src_28000.ds) AS view__ds__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds) AS view__ds__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds) AS view__ds__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__day - , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__week - , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__year - , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_doy - , views_source_src_28000.listing_id AS listing - , views_source_src_28000.user_id AS user - , views_source_src_28000.listing_id AS view__listing - , views_source_src_28000.user_id AS view__user - FROM ***************************.fct_views views_source_src_28000 - ) subq_12 - ) subq_13 - ) subq_14 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] - SELECT - subq_16.listing - , subq_16.is_lux_latest - , subq_16.capacity_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 - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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 - ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 - WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) - ) subq_20 - ) subq_21 + 1 AS views + , DATE_TRUNC('day', views_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', views_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', views_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', views_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', views_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM views_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM views_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds) AS view__ds__day + , DATE_TRUNC('week', views_source_src_28000.ds) AS view__ds__week + , DATE_TRUNC('month', views_source_src_28000.ds) AS view__ds__month + , DATE_TRUNC('quarter', views_source_src_28000.ds) AS view__ds__quarter + , DATE_TRUNC('year', views_source_src_28000.ds) AS view__ds__year + , EXTRACT(year FROM views_source_src_28000.ds) AS view__ds__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds) AS view__ds__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds) AS view__ds__extract_month + , EXTRACT(day FROM views_source_src_28000.ds) AS view__ds__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds) AS view__ds__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds) AS view__ds__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__day + , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__week + , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__year + , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_doy + , views_source_src_28000.listing_id AS listing + , views_source_src_28000.user_id AS user + , views_source_src_28000.listing_id AS view__listing + , views_source_src_28000.user_id AS view__user + FROM ***************************.fct_views views_source_src_28000 + ) subq_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_10.listing + , subq_10.is_lux_latest + , subq_10.capacity_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_10 + ) subq_11 + ON + subq_9.listing = subq_11.listing + ) subq_12 + WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) + ) subq_13 GROUP BY - subq_21.listing__capacity_latest - ) subq_22 -) subq_23 + subq_13.listing__capacity_latest + ) subq_14 +) subq_15 ON - subq_11.listing__capacity_latest = subq_23.listing__capacity_latest + subq_7.listing__capacity_latest = subq_15.listing__capacity_latest FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_48.listing__capacity_latest - , CAST(subq_48.bookings AS DOUBLE) / CAST(NULLIF(subq_48.views, 0) AS DOUBLE) AS bookings_per_view + subq_32.listing__capacity_latest + , CAST(subq_32.bookings AS DOUBLE) / CAST(NULLIF(subq_32.views, 0) AS DOUBLE) AS bookings_per_view FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_35.listing__capacity_latest, subq_47.listing__capacity_latest) AS listing__capacity_latest - , MAX(subq_35.bookings) AS bookings - , MAX(subq_47.views) AS views + COALESCE(subq_23.listing__capacity_latest, subq_31.listing__capacity_latest) AS listing__capacity_latest + , MAX(subq_23.bookings) AS bookings + , MAX(subq_31.views) AS views FROM ( -- Compute Metrics via Expressions SELECT - subq_34.listing__capacity_latest - , subq_34.bookings + subq_22.listing__capacity_latest + , subq_22.bookings FROM ( -- Aggregate Measures SELECT - subq_33.listing__capacity_latest - , SUM(subq_33.bookings) AS bookings + subq_21.listing__capacity_latest + , SUM(subq_21.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__capacity_latest'] SELECT - subq_32.listing__capacity_latest - , subq_32.bookings + subq_20.listing__capacity_latest + , subq_20.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_31.metric_time__day - , subq_31.listing__is_lux_latest - , subq_31.listing__capacity_latest - , subq_31.bookings + subq_17.metric_time__day AS metric_time__day + , subq_17.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] SELECT - subq_30.metric_time__day - , subq_30.listing__is_lux_latest - , subq_30.listing__capacity_latest - , subq_30.bookings + subq_16.ds__day AS metric_time__day + , subq_16.listing + , subq_16.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_26.metric_time__day AS metric_time__day - , subq_26.listing AS listing - , subq_29.is_lux_latest AS listing__is_lux_latest - , subq_29.capacity_latest AS listing__capacity_latest - , subq_26.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] - SELECT - subq_25.metric_time__day - , subq_25.listing - , subq_25.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 - 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_24 - ) subq_25 - ) subq_26 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] - SELECT - subq_28.listing - , subq_28.is_lux_latest - , subq_28.capacity_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_27.ds__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.created_at__day - , subq_27.created_at__week - , subq_27.created_at__month - , subq_27.created_at__quarter - , subq_27.created_at__year - , subq_27.created_at__extract_year - , subq_27.created_at__extract_quarter - , subq_27.created_at__extract_month - , subq_27.created_at__extract_day - , subq_27.created_at__extract_dow - , subq_27.created_at__extract_doy - , subq_27.listing__ds__day - , subq_27.listing__ds__week - , subq_27.listing__ds__month - , subq_27.listing__ds__quarter - , subq_27.listing__ds__year - , subq_27.listing__ds__extract_year - , subq_27.listing__ds__extract_quarter - , subq_27.listing__ds__extract_month - , subq_27.listing__ds__extract_day - , subq_27.listing__ds__extract_dow - , subq_27.listing__ds__extract_doy - , subq_27.listing__created_at__day - , subq_27.listing__created_at__week - , subq_27.listing__created_at__month - , subq_27.listing__created_at__quarter - , subq_27.listing__created_at__year - , subq_27.listing__created_at__extract_year - , subq_27.listing__created_at__extract_quarter - , subq_27.listing__created_at__extract_month - , subq_27.listing__created_at__extract_day - , subq_27.listing__created_at__extract_dow - , subq_27.listing__created_at__extract_doy - , subq_27.ds__day AS metric_time__day - , subq_27.ds__week AS metric_time__week - , subq_27.ds__month AS metric_time__month - , subq_27.ds__quarter AS metric_time__quarter - , subq_27.ds__year AS metric_time__year - , subq_27.ds__extract_year AS metric_time__extract_year - , subq_27.ds__extract_quarter AS metric_time__extract_quarter - , subq_27.ds__extract_month AS metric_time__extract_month - , subq_27.ds__extract_day AS metric_time__extract_day - , subq_27.ds__extract_dow AS metric_time__extract_dow - , subq_27.ds__extract_doy AS metric_time__extract_doy - , subq_27.listing - , subq_27.user - , subq_27.listing__user - , subq_27.country_latest - , subq_27.is_lux_latest - , subq_27.capacity_latest - , subq_27.listing__country_latest - , subq_27.listing__is_lux_latest - , subq_27.listing__capacity_latest - , subq_27.listings - , subq_27.largest_listing - , subq_27.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_27 - ) subq_28 - ) subq_29 - ON - subq_26.listing = subq_29.listing - ) subq_30 - ) subq_31 - WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) - ) subq_32 - ) subq_33 + 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_16 + ) subq_17 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_18.listing + , subq_18.is_lux_latest + , subq_18.capacity_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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 + ON + subq_17.listing = subq_19.listing + ) subq_20 + WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) + ) subq_21 GROUP BY - subq_33.listing__capacity_latest - ) subq_34 - ) subq_35 + subq_21.listing__capacity_latest + ) subq_22 + ) subq_23 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_46.listing__capacity_latest - , subq_46.views + subq_30.listing__capacity_latest + , subq_30.views FROM ( -- Aggregate Measures SELECT - subq_45.listing__capacity_latest - , SUM(subq_45.views) AS views + subq_29.listing__capacity_latest + , SUM(subq_29.views) AS views FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['views', 'listing__capacity_latest'] SELECT - subq_44.listing__capacity_latest - , subq_44.views + subq_28.listing__capacity_latest + , subq_28.views FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['views', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_43.metric_time__day - , subq_43.listing__is_lux_latest - , subq_43.listing__capacity_latest - , subq_43.views + subq_25.metric_time__day AS metric_time__day + , subq_25.views AS views FROM ( - -- Pass Only Elements: ['views', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['views', 'metric_time__day', 'listing'] SELECT - subq_42.metric_time__day - , subq_42.listing__is_lux_latest - , subq_42.listing__capacity_latest - , subq_42.views + subq_24.ds__day AS metric_time__day + , subq_24.listing + , subq_24.views FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'views_source' SELECT - subq_38.metric_time__day AS metric_time__day - , subq_38.listing AS listing - , subq_41.is_lux_latest AS listing__is_lux_latest - , subq_41.capacity_latest AS listing__capacity_latest - , subq_38.views AS views - FROM ( - -- Pass Only Elements: ['views', 'metric_time__day', 'listing'] - SELECT - subq_37.metric_time__day - , subq_37.listing - , subq_37.views - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_36.ds__day - , subq_36.ds__week - , subq_36.ds__month - , subq_36.ds__quarter - , subq_36.ds__year - , subq_36.ds__extract_year - , subq_36.ds__extract_quarter - , subq_36.ds__extract_month - , subq_36.ds__extract_day - , subq_36.ds__extract_dow - , subq_36.ds__extract_doy - , subq_36.ds_partitioned__day - , subq_36.ds_partitioned__week - , subq_36.ds_partitioned__month - , subq_36.ds_partitioned__quarter - , subq_36.ds_partitioned__year - , subq_36.ds_partitioned__extract_year - , subq_36.ds_partitioned__extract_quarter - , subq_36.ds_partitioned__extract_month - , subq_36.ds_partitioned__extract_day - , subq_36.ds_partitioned__extract_dow - , subq_36.ds_partitioned__extract_doy - , subq_36.view__ds__day - , subq_36.view__ds__week - , subq_36.view__ds__month - , subq_36.view__ds__quarter - , subq_36.view__ds__year - , subq_36.view__ds__extract_year - , subq_36.view__ds__extract_quarter - , subq_36.view__ds__extract_month - , subq_36.view__ds__extract_day - , subq_36.view__ds__extract_dow - , subq_36.view__ds__extract_doy - , subq_36.view__ds_partitioned__day - , subq_36.view__ds_partitioned__week - , subq_36.view__ds_partitioned__month - , subq_36.view__ds_partitioned__quarter - , subq_36.view__ds_partitioned__year - , subq_36.view__ds_partitioned__extract_year - , subq_36.view__ds_partitioned__extract_quarter - , subq_36.view__ds_partitioned__extract_month - , subq_36.view__ds_partitioned__extract_day - , subq_36.view__ds_partitioned__extract_dow - , subq_36.view__ds_partitioned__extract_doy - , subq_36.ds__day AS metric_time__day - , subq_36.ds__week AS metric_time__week - , subq_36.ds__month AS metric_time__month - , subq_36.ds__quarter AS metric_time__quarter - , subq_36.ds__year AS metric_time__year - , subq_36.ds__extract_year AS metric_time__extract_year - , subq_36.ds__extract_quarter AS metric_time__extract_quarter - , subq_36.ds__extract_month AS metric_time__extract_month - , subq_36.ds__extract_day AS metric_time__extract_day - , subq_36.ds__extract_dow AS metric_time__extract_dow - , subq_36.ds__extract_doy AS metric_time__extract_doy - , subq_36.listing - , subq_36.user - , subq_36.view__listing - , subq_36.view__user - , subq_36.views - FROM ( - -- Read Elements From Semantic Model 'views_source' - SELECT - 1 AS views - , DATE_TRUNC('day', views_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', views_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', views_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', views_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', views_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM views_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM views_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds) AS view__ds__day - , DATE_TRUNC('week', views_source_src_28000.ds) AS view__ds__week - , DATE_TRUNC('month', views_source_src_28000.ds) AS view__ds__month - , DATE_TRUNC('quarter', views_source_src_28000.ds) AS view__ds__quarter - , DATE_TRUNC('year', views_source_src_28000.ds) AS view__ds__year - , EXTRACT(year FROM views_source_src_28000.ds) AS view__ds__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds) AS view__ds__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds) AS view__ds__extract_month - , EXTRACT(day FROM views_source_src_28000.ds) AS view__ds__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds) AS view__ds__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds) AS view__ds__extract_doy - , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__day - , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__week - , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__month - , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__quarter - , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__year - , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_year - , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_quarter - , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_month - , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_day - , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_dow - , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_doy - , views_source_src_28000.listing_id AS listing - , views_source_src_28000.user_id AS user - , views_source_src_28000.listing_id AS view__listing - , views_source_src_28000.user_id AS view__user - FROM ***************************.fct_views views_source_src_28000 - ) subq_36 - ) subq_37 - ) subq_38 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] - SELECT - subq_40.listing - , subq_40.is_lux_latest - , subq_40.capacity_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_39.ds__day - , subq_39.ds__week - , subq_39.ds__month - , subq_39.ds__quarter - , subq_39.ds__year - , subq_39.ds__extract_year - , subq_39.ds__extract_quarter - , subq_39.ds__extract_month - , subq_39.ds__extract_day - , subq_39.ds__extract_dow - , subq_39.ds__extract_doy - , subq_39.created_at__day - , subq_39.created_at__week - , subq_39.created_at__month - , subq_39.created_at__quarter - , subq_39.created_at__year - , subq_39.created_at__extract_year - , subq_39.created_at__extract_quarter - , subq_39.created_at__extract_month - , subq_39.created_at__extract_day - , subq_39.created_at__extract_dow - , subq_39.created_at__extract_doy - , subq_39.listing__ds__day - , subq_39.listing__ds__week - , subq_39.listing__ds__month - , subq_39.listing__ds__quarter - , subq_39.listing__ds__year - , subq_39.listing__ds__extract_year - , subq_39.listing__ds__extract_quarter - , subq_39.listing__ds__extract_month - , subq_39.listing__ds__extract_day - , subq_39.listing__ds__extract_dow - , subq_39.listing__ds__extract_doy - , subq_39.listing__created_at__day - , subq_39.listing__created_at__week - , subq_39.listing__created_at__month - , subq_39.listing__created_at__quarter - , subq_39.listing__created_at__year - , subq_39.listing__created_at__extract_year - , subq_39.listing__created_at__extract_quarter - , subq_39.listing__created_at__extract_month - , subq_39.listing__created_at__extract_day - , subq_39.listing__created_at__extract_dow - , subq_39.listing__created_at__extract_doy - , subq_39.ds__day AS metric_time__day - , subq_39.ds__week AS metric_time__week - , subq_39.ds__month AS metric_time__month - , subq_39.ds__quarter AS metric_time__quarter - , subq_39.ds__year AS metric_time__year - , subq_39.ds__extract_year AS metric_time__extract_year - , subq_39.ds__extract_quarter AS metric_time__extract_quarter - , subq_39.ds__extract_month AS metric_time__extract_month - , subq_39.ds__extract_day AS metric_time__extract_day - , subq_39.ds__extract_dow AS metric_time__extract_dow - , subq_39.ds__extract_doy AS metric_time__extract_doy - , subq_39.listing - , subq_39.user - , subq_39.listing__user - , subq_39.country_latest - , subq_39.is_lux_latest - , subq_39.capacity_latest - , subq_39.listing__country_latest - , subq_39.listing__is_lux_latest - , subq_39.listing__capacity_latest - , subq_39.listings - , subq_39.largest_listing - , subq_39.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_39 - ) subq_40 - ) subq_41 - ON - subq_38.listing = subq_41.listing - ) subq_42 - ) subq_43 - WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) - ) subq_44 - ) subq_45 + 1 AS views + , DATE_TRUNC('day', views_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', views_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', views_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', views_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', views_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM views_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM views_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds) AS view__ds__day + , DATE_TRUNC('week', views_source_src_28000.ds) AS view__ds__week + , DATE_TRUNC('month', views_source_src_28000.ds) AS view__ds__month + , DATE_TRUNC('quarter', views_source_src_28000.ds) AS view__ds__quarter + , DATE_TRUNC('year', views_source_src_28000.ds) AS view__ds__year + , EXTRACT(year FROM views_source_src_28000.ds) AS view__ds__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds) AS view__ds__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds) AS view__ds__extract_month + , EXTRACT(day FROM views_source_src_28000.ds) AS view__ds__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds) AS view__ds__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds) AS view__ds__extract_doy + , DATE_TRUNC('day', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__day + , DATE_TRUNC('week', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__week + , DATE_TRUNC('month', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__month + , DATE_TRUNC('quarter', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__quarter + , DATE_TRUNC('year', views_source_src_28000.ds_partitioned) AS view__ds_partitioned__year + , EXTRACT(year FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_year + , EXTRACT(quarter FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_quarter + , EXTRACT(month FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_month + , EXTRACT(day FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_day + , EXTRACT(isodow FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_dow + , EXTRACT(doy FROM views_source_src_28000.ds_partitioned) AS view__ds_partitioned__extract_doy + , views_source_src_28000.listing_id AS listing + , views_source_src_28000.user_id AS user + , views_source_src_28000.listing_id AS view__listing + , views_source_src_28000.user_id AS view__user + FROM ***************************.fct_views views_source_src_28000 + ) subq_24 + ) subq_25 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['capacity_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_26.listing + , subq_26.is_lux_latest + , subq_26.capacity_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_26 + ) subq_27 + ON + subq_25.listing = subq_27.listing + ) subq_28 + WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) + ) subq_29 GROUP BY - subq_45.listing__capacity_latest - ) subq_46 - ) subq_47 + subq_29.listing__capacity_latest + ) subq_30 + ) subq_31 ON - subq_35.listing__capacity_latest = subq_47.listing__capacity_latest + subq_23.listing__capacity_latest = subq_31.listing__capacity_latest GROUP BY - COALESCE(subq_35.listing__capacity_latest, subq_47.listing__capacity_latest) - ) subq_48 -) subq_49 + COALESCE(subq_23.listing__capacity_latest, subq_31.listing__capacity_latest) + ) subq_32 +) subq_33 ON - COALESCE(subq_11.listing__capacity_latest, subq_23.listing__capacity_latest) = subq_49.listing__capacity_latest + COALESCE(subq_7.listing__capacity_latest, subq_15.listing__capacity_latest) = subq_33.listing__capacity_latest GROUP BY - COALESCE(subq_11.listing__capacity_latest, subq_23.listing__capacity_latest, subq_49.listing__capacity_latest) + COALESCE(subq_7.listing__capacity_latest, subq_15.listing__capacity_latest, subq_33.listing__capacity_latest) diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0_optimized.sql index 062477fe3c..5421e250a4 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_saved_query_with_metric_joins_and_filter__plan0_optimized.sql @@ -1,9 +1,9 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_61.listing__capacity_latest, subq_73.listing__capacity_latest, subq_98.listing__capacity_latest) AS listing__capacity_latest - , MAX(subq_61.bookings) AS bookings - , MAX(subq_73.views) AS views - , MAX(CAST(subq_98.bookings AS DOUBLE) / CAST(NULLIF(subq_98.views, 0) AS DOUBLE)) AS bookings_per_view + COALESCE(subq_41.listing__capacity_latest, subq_49.listing__capacity_latest, subq_66.listing__capacity_latest) AS listing__capacity_latest + , MAX(subq_41.bookings) AS bookings + , MAX(subq_49.views) AS views + , MAX(CAST(subq_66.bookings AS DOUBLE) / CAST(NULLIF(subq_66.views, 0) AS DOUBLE)) AS bookings_per_view FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__capacity_latest'] @@ -16,10 +16,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_52.metric_time__day AS metric_time__day - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , subq_52.bookings AS bookings + subq_35.metric_time__day AS metric_time__day + , subq_35.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -29,16 +27,16 @@ FROM ( , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_52 + ) subq_35 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_52.listing = listings_latest_src_28000.listing_id - ) subq_57 + subq_35.listing = listings_latest_src_28000.listing_id + ) subq_38 WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) GROUP BY listing__capacity_latest -) subq_61 +) subq_41 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['views', 'listing__capacity_latest'] @@ -51,10 +49,8 @@ FULL OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['views', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_64.metric_time__day AS metric_time__day - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , subq_64.views AS views + subq_43.metric_time__day AS metric_time__day + , subq_43.views AS views FROM ( -- Read Elements From Semantic Model 'views_source' -- Metric Time Dimension 'ds' @@ -64,24 +60,24 @@ FULL OUTER JOIN ( , listing_id AS listing , 1 AS views FROM ***************************.fct_views views_source_src_28000 - ) subq_64 + ) subq_43 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_64.listing = listings_latest_src_28000.listing_id - ) subq_69 + subq_43.listing = listings_latest_src_28000.listing_id + ) subq_46 WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) GROUP BY listing__capacity_latest -) subq_73 +) subq_49 ON - subq_61.listing__capacity_latest = subq_73.listing__capacity_latest + subq_41.listing__capacity_latest = subq_49.listing__capacity_latest FULL OUTER JOIN ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_85.listing__capacity_latest, subq_97.listing__capacity_latest) AS listing__capacity_latest - , MAX(subq_85.bookings) AS bookings - , MAX(subq_97.views) AS views + COALESCE(subq_57.listing__capacity_latest, subq_65.listing__capacity_latest) AS listing__capacity_latest + , MAX(subq_57.bookings) AS bookings + , MAX(subq_65.views) AS views FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__capacity_latest'] @@ -94,10 +90,8 @@ FULL OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_76.metric_time__day AS metric_time__day - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , subq_76.bookings AS bookings + subq_51.metric_time__day AS metric_time__day + , subq_51.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -107,16 +101,16 @@ FULL OUTER JOIN ( , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_76 + ) subq_51 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_76.listing = listings_latest_src_28000.listing_id - ) subq_81 + subq_51.listing = listings_latest_src_28000.listing_id + ) subq_54 WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) GROUP BY listing__capacity_latest - ) subq_85 + ) subq_57 FULL OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['views', 'listing__capacity_latest'] @@ -129,10 +123,8 @@ FULL OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['views', 'listing__capacity_latest', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_88.metric_time__day AS metric_time__day - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , subq_88.views AS views + subq_59.metric_time__day AS metric_time__day + , subq_59.views AS views FROM ( -- Read Elements From Semantic Model 'views_source' -- Metric Time Dimension 'ds' @@ -142,22 +134,22 @@ FULL OUTER JOIN ( , listing_id AS listing , 1 AS views FROM ***************************.fct_views views_source_src_28000 - ) subq_88 + ) subq_59 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_88.listing = listings_latest_src_28000.listing_id - ) subq_93 + subq_59.listing = listings_latest_src_28000.listing_id + ) subq_62 WHERE ( listing__is_lux_latest ) AND ( metric_time__day >= '2020-01-02' ) GROUP BY listing__capacity_latest - ) subq_97 + ) subq_65 ON - subq_85.listing__capacity_latest = subq_97.listing__capacity_latest + subq_57.listing__capacity_latest = subq_65.listing__capacity_latest GROUP BY - COALESCE(subq_85.listing__capacity_latest, subq_97.listing__capacity_latest) -) subq_98 + COALESCE(subq_57.listing__capacity_latest, subq_65.listing__capacity_latest) +) subq_66 ON - COALESCE(subq_61.listing__capacity_latest, subq_73.listing__capacity_latest) = subq_98.listing__capacity_latest + COALESCE(subq_41.listing__capacity_latest, subq_49.listing__capacity_latest) = subq_66.listing__capacity_latest GROUP BY - COALESCE(subq_61.listing__capacity_latest, subq_73.listing__capacity_latest, subq_98.listing__capacity_latest) + COALESCE(subq_41.listing__capacity_latest, subq_49.listing__capacity_latest, subq_66.listing__capacity_latest) 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 00f2cc5ddb..8daa8f684c 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 @@ -1,248 +1,147 @@ -- 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_7.metric_time__day + , subq_7.booking__is_instant + , subq_7.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_6.metric_time__day + , subq_6.booking__is_instant + , subq_6.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_4.metric_time__day AS metric_time__day + , subq_3.booking__is_instant AS booking__is_instant + , subq_3.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_2.metric_time__day + , subq_2.booking__is_instant + , SUM(subq_2.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_1.metric_time__day + , subq_1.booking__is_instant + , subq_1.bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 WHERE booking__is_instant - ) subq_3 + ) subq_2 GROUP BY - subq_3.metric_time__day - , subq_3.booking__is_instant - ) subq_4 + subq_2.metric_time__day + , subq_2.booking__is_instant + ) subq_3 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_4.metric_time__day = subq_3.metric_time__day + ) subq_6 WHERE booking__is_instant -) subq_8 +) subq_7 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 6e8a46fe3b..89d72dc920 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 @@ -7,10 +7,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 + subq_13.ds AS metric_time__day + , subq_11.booking__is_instant AS booking__is_instant + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -27,13 +27,13 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_9 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_11 ON - subq_15.ds = subq_13.metric_time__day -) subq_16 + subq_13.ds = subq_11.metric_time__day +) subq_14 WHERE booking__is_instant diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0.sql index 14aba1afb1..1b2e6e7e13 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0.sql @@ -1,383 +1,198 @@ -- Compute Metrics via Expressions SELECT - subq_10.listing__country_latest - , subq_10.bookings + subq_6.listing__country_latest + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_9.listing__country_latest - , SUM(subq_9.bookings) AS bookings + subq_5.listing__country_latest + , SUM(subq_5.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest'] SELECT - subq_8.listing__country_latest - , subq_8.bookings + subq_4.listing__country_latest + , subq_4.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] SELECT - subq_7.booking__is_instant - , subq_7.listing__country_latest - , subq_7.bookings + subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_6.booking__is_instant - , subq_6.listing__country_latest - , subq_6.bookings + subq_0.listing + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.country_latest AS listing__country_latest - , subq_2.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] - SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] - SELECT - subq_4.listing - , subq_4.country_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE booking__is_instant - ) subq_8 - ) subq_9 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_2.listing + , subq_2.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE booking__is_instant + ) subq_5 GROUP BY - subq_9.listing__country_latest -) subq_10 + subq_5.listing__country_latest +) subq_6 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0_optimized.sql index 31b5d1e8d5..66ce5e92d7 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_single_categorical_dimension_pushdown__plan0_optimized.sql @@ -9,9 +9,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant'] SELECT - subq_13.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.country AS listing__country_latest - , subq_13.bookings AS bookings + subq_8.booking__is_instant AS booking__is_instant + , subq_8.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -21,12 +20,12 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_8 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_13.listing = listings_latest_src_28000.listing_id -) subq_18 + subq_8.listing = listings_latest_src_28000.listing_id +) subq_11 WHERE booking__is_instant GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql index a62b838b8c..2f7a152329 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0.sql @@ -1,387 +1,199 @@ -- Compute Metrics via Expressions SELECT - subq_10.listing__country_latest - , subq_10.bookings + subq_6.listing__country_latest + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_9.listing__country_latest - , SUM(subq_9.bookings) AS bookings + subq_5.listing__country_latest + , SUM(subq_5.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'listing__country_latest'] SELECT - subq_8.listing__country_latest - , subq_8.bookings + subq_4.listing__country_latest + , subq_4.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] SELECT - subq_7.booking__is_instant - , subq_7.listing__country_latest - , subq_7.listing__is_lux_latest - , subq_7.bookings + subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_6.booking__is_instant - , subq_6.listing__country_latest - , subq_6.listing__is_lux_latest - , subq_6.bookings + subq_0.listing + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.country_latest AS listing__country_latest - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] - SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] - SELECT - subq_4.listing - , subq_4.country_latest - , subq_4.is_lux_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE booking__is_instant OR listing__is_lux_latest - ) subq_8 - ) subq_9 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'is_lux_latest', 'listing', 'listing'] + SELECT + subq_2.listing + , subq_2.country_latest + , subq_2.is_lux_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE booking__is_instant OR listing__is_lux_latest + ) subq_5 GROUP BY - subq_9.listing__country_latest -) subq_10 + subq_5.listing__country_latest +) subq_6 diff --git a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0_optimized.sql b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0_optimized.sql index be31b01767..b11cac6d80 100644 --- a/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_predicate_pushdown_rendering.py/SqlQueryPlan/DuckDB/test_skipped_pushdown__plan0_optimized.sql @@ -9,10 +9,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__country_latest', 'booking__is_instant', 'listing__is_lux_latest'] SELECT - subq_13.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_13.bookings AS bookings + subq_8.booking__is_instant AS booking__is_instant + , subq_8.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -22,12 +20,12 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_8 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_13.listing = listings_latest_src_28000.listing_id -) subq_18 + subq_8.listing = listings_latest_src_28000.listing_id +) subq_11 WHERE booking__is_instant OR listing__is_lux_latest GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_common_semantic_model__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_common_semantic_model__plan0.sql index 017e521eaa..300c331f05 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_common_semantic_model__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_common_semantic_model__plan0.sql @@ -1,439 +1,237 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day - , MAX(subq_4.bookings) AS bookings - , MAX(subq_9.booking_value) AS booking_value + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) AS metric_time__day + , MAX(subq_3.bookings) AS bookings + , MAX(subq_7.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_2.metric_time__day + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 -) subq_4 + subq_1.metric_time__day + ) subq_2 +) subq_3 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , subq_8.booking_value + subq_6.metric_time__day + , subq_6.booking_value FROM ( -- Aggregate Measures SELECT - subq_7.metric_time__day - , SUM(subq_7.booking_value) AS booking_value + subq_5.metric_time__day + , SUM(subq_5.booking_value) AS booking_value FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.booking_value + subq_4.ds__day AS metric_time__day + , subq_4.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.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.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.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 ( - -- 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_5 - ) subq_6 - ) subq_7 + 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_4 + ) subq_5 GROUP BY - subq_7.metric_time__day - ) subq_8 -) subq_9 + subq_5.metric_time__day + ) subq_6 +) subq_7 ON - subq_4.metric_time__day = subq_9.metric_time__day + subq_3.metric_time__day = subq_7.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_common_semantic_model__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_common_semantic_model__plan0_optimized.sql index e0c3b7024e..ef4aa00f77 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_common_semantic_model__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_common_semantic_model__plan0_optimized.sql @@ -13,6 +13,6 @@ FROM ( , 1 AS bookings , booking_value FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_12 +) subq_9 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values__plan0.sql index cd3d4c172a..16db2b1880 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values__plan0.sql @@ -1,134 +1,75 @@ -- Order By ['listing__country_latest'] Limit 100 SELECT - subq_2.listing__country_latest + subq_1.listing__country_latest FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['listing__country_latest',] SELECT - subq_1.listing__country_latest + subq_0.listing__country_latest FROM ( - -- Constrain Output with WHERE + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_at__extract_doy - , subq_0.listing - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - WHERE listing__country_latest = 'us' - ) subq_1 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + WHERE listing__country_latest = 'us' GROUP BY - subq_1.listing__country_latest -) subq_2 -ORDER BY subq_2.listing__country_latest DESC + subq_0.listing__country_latest +) subq_1 +ORDER BY subq_1.listing__country_latest DESC LIMIT 100 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values__plan0_optimized.sql index 1653ada5bd..215ea9b08c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_distinct_values__plan0_optimized.sql @@ -8,7 +8,7 @@ FROM ( SELECT country AS listing__country_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_3 +) subq_2 WHERE listing__country_latest = 'us' GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_on_join_dim__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_on_join_dim__plan0.sql index b8f95359e6..5704b60021 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_on_join_dim__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_on_join_dim__plan0.sql @@ -1,383 +1,198 @@ -- Compute Metrics via Expressions SELECT - subq_10.booking__is_instant - , subq_10.bookings + subq_6.booking__is_instant + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_9.booking__is_instant - , SUM(subq_9.bookings) AS bookings + subq_5.booking__is_instant + , SUM(subq_5.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'booking__is_instant'] SELECT - subq_8.booking__is_instant - , subq_8.bookings + subq_4.booking__is_instant + , subq_4.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__country_latest'] SELECT - subq_7.booking__is_instant - , subq_7.listing__country_latest - , subq_7.bookings + subq_1.booking__is_instant AS booking__is_instant + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__country_latest'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] SELECT - subq_6.booking__is_instant - , subq_6.listing__country_latest - , subq_6.bookings + subq_0.listing + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.listing AS listing - , subq_2.booking__is_instant AS booking__is_instant - , subq_5.country_latest AS listing__country_latest - , subq_2.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing'] - SELECT - subq_1.listing - , subq_1.booking__is_instant - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['country_latest', 'listing'] - SELECT - subq_4.listing - , subq_4.country_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE listing__country_latest = 'us' - ) subq_8 - ) subq_9 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['country_latest', 'listing'] + SELECT + subq_2.listing + , subq_2.country_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE listing__country_latest = 'us' + ) subq_5 GROUP BY - subq_9.booking__is_instant -) subq_10 + subq_5.booking__is_instant +) subq_6 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql index 9a9173fe96..74e7572985 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_filter_with_where_constraint_on_join_dim__plan0_optimized.sql @@ -9,9 +9,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'booking__is_instant', 'listing__country_latest'] SELECT - subq_13.booking__is_instant AS booking__is_instant - , listings_latest_src_28000.country AS listing__country_latest - , subq_13.bookings AS bookings + subq_8.booking__is_instant AS booking__is_instant + , subq_8.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -21,12 +20,12 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_13 + ) subq_8 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_13.listing = listings_latest_src_28000.listing_id -) subq_18 + subq_8.listing = listings_latest_src_28000.listing_id +) subq_11 WHERE listing__country_latest = 'us' GROUP BY booking__is_instant diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0.sql index ee768657d4..6065541ccb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0.sql @@ -1,313 +1,146 @@ -- Compute Metrics via Expressions SELECT - subq_9.metric_time__day - , subq_9.bookings AS family_bookings + subq_5.metric_time__day + , subq_5.bookings AS family_bookings FROM ( -- Aggregate Measures SELECT - subq_8.metric_time__day - , SUM(subq_8.bookings) AS bookings + subq_4.metric_time__day + , SUM(subq_4.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.bookings + subq_3.metric_time__day + , subq_3.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__capacity', 'metric_time__day'] SELECT - subq_6.metric_time__day - , subq_6.listing__capacity - , subq_6.bookings + subq_1.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__capacity', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] SELECT - subq_5.metric_time__day - , subq_5.listing__capacity - , subq_5.bookings + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.bookings FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_4.window_start__day AS listing__window_start__day - , subq_4.window_end__day AS listing__window_end__day - , subq_2.listing AS listing - , subq_4.capacity AS listing__capacity - , subq_2.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] - SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.user - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.booking__user - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.bookers - , subq_0.average_booking_value - 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_26000.booking_value - , bookings_source_src_26000.guest_id AS bookers - , bookings_source_src_26000.booking_value AS average_booking_value - , bookings_source_src_26000.booking_value AS booking_payments - , bookings_source_src_26000.is_instant - , DATE_TRUNC('day', bookings_source_src_26000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_26000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_26000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_26000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds) AS ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS paid_at__extract_doy - , bookings_source_src_26000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_26000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_26000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_26000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_26000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds) AS booking__ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_26000.listing_id AS listing - , bookings_source_src_26000.guest_id AS guest - , bookings_source_src_26000.host_id AS host - , bookings_source_src_26000.guest_id AS user - , bookings_source_src_26000.listing_id AS booking__listing - , bookings_source_src_26000.guest_id AS booking__guest - , bookings_source_src_26000.host_id AS booking__host - , bookings_source_src_26000.guest_id AS booking__user - FROM ***************************.fct_bookings bookings_source_src_26000 - ) subq_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['capacity', 'window_start__day', 'window_end__day', 'listing'] - SELECT - subq_3.window_start__day - , subq_3.window_end__day - , subq_3.listing - , subq_3.capacity - FROM ( - -- Read Elements From Semantic Model 'listings' - SELECT - listings_src_26000.active_from AS window_start__day - , DATE_TRUNC('week', listings_src_26000.active_from) AS window_start__week - , DATE_TRUNC('month', listings_src_26000.active_from) AS window_start__month - , DATE_TRUNC('quarter', listings_src_26000.active_from) AS window_start__quarter - , DATE_TRUNC('year', listings_src_26000.active_from) AS window_start__year - , EXTRACT(year FROM listings_src_26000.active_from) AS window_start__extract_year - , EXTRACT(quarter FROM listings_src_26000.active_from) AS window_start__extract_quarter - , EXTRACT(month FROM listings_src_26000.active_from) AS window_start__extract_month - , EXTRACT(day FROM listings_src_26000.active_from) AS window_start__extract_day - , EXTRACT(isodow FROM listings_src_26000.active_from) AS window_start__extract_dow - , EXTRACT(doy FROM listings_src_26000.active_from) AS window_start__extract_doy - , listings_src_26000.active_to AS window_end__day - , DATE_TRUNC('week', listings_src_26000.active_to) AS window_end__week - , DATE_TRUNC('month', listings_src_26000.active_to) AS window_end__month - , DATE_TRUNC('quarter', listings_src_26000.active_to) AS window_end__quarter - , DATE_TRUNC('year', listings_src_26000.active_to) AS window_end__year - , EXTRACT(year FROM listings_src_26000.active_to) AS window_end__extract_year - , EXTRACT(quarter FROM listings_src_26000.active_to) AS window_end__extract_quarter - , EXTRACT(month FROM listings_src_26000.active_to) AS window_end__extract_month - , EXTRACT(day FROM listings_src_26000.active_to) AS window_end__extract_day - , EXTRACT(isodow FROM listings_src_26000.active_to) AS window_end__extract_dow - , EXTRACT(doy FROM listings_src_26000.active_to) AS window_end__extract_doy - , listings_src_26000.country - , listings_src_26000.is_lux - , listings_src_26000.capacity - , listings_src_26000.active_from AS listing__window_start__day - , DATE_TRUNC('week', listings_src_26000.active_from) AS listing__window_start__week - , DATE_TRUNC('month', listings_src_26000.active_from) AS listing__window_start__month - , DATE_TRUNC('quarter', listings_src_26000.active_from) AS listing__window_start__quarter - , DATE_TRUNC('year', listings_src_26000.active_from) AS listing__window_start__year - , EXTRACT(year FROM listings_src_26000.active_from) AS listing__window_start__extract_year - , EXTRACT(quarter FROM listings_src_26000.active_from) AS listing__window_start__extract_quarter - , EXTRACT(month FROM listings_src_26000.active_from) AS listing__window_start__extract_month - , EXTRACT(day FROM listings_src_26000.active_from) AS listing__window_start__extract_day - , EXTRACT(isodow FROM listings_src_26000.active_from) AS listing__window_start__extract_dow - , EXTRACT(doy FROM listings_src_26000.active_from) AS listing__window_start__extract_doy - , listings_src_26000.active_to AS listing__window_end__day - , DATE_TRUNC('week', listings_src_26000.active_to) AS listing__window_end__week - , DATE_TRUNC('month', listings_src_26000.active_to) AS listing__window_end__month - , DATE_TRUNC('quarter', listings_src_26000.active_to) AS listing__window_end__quarter - , DATE_TRUNC('year', listings_src_26000.active_to) AS listing__window_end__year - , EXTRACT(year FROM listings_src_26000.active_to) AS listing__window_end__extract_year - , EXTRACT(quarter FROM listings_src_26000.active_to) AS listing__window_end__extract_quarter - , EXTRACT(month FROM listings_src_26000.active_to) AS listing__window_end__extract_month - , EXTRACT(day FROM listings_src_26000.active_to) AS listing__window_end__extract_day - , EXTRACT(isodow FROM listings_src_26000.active_to) AS listing__window_end__extract_dow - , EXTRACT(doy FROM listings_src_26000.active_to) AS listing__window_end__extract_doy - , listings_src_26000.country AS listing__country - , listings_src_26000.is_lux AS listing__is_lux - , listings_src_26000.capacity AS listing__capacity - , listings_src_26000.listing_id AS listing - , listings_src_26000.user_id AS user - , listings_src_26000.user_id AS listing__user - FROM ***************************.dim_listings listings_src_26000 - ) subq_3 - ) subq_4 - ON + 1 AS bookings + , CASE WHEN is_instant THEN 1 ELSE 0 END AS instant_bookings + , bookings_source_src_26000.booking_value + , bookings_source_src_26000.guest_id AS bookers + , bookings_source_src_26000.booking_value AS average_booking_value + , bookings_source_src_26000.booking_value AS booking_payments + , bookings_source_src_26000.is_instant + , DATE_TRUNC('day', bookings_source_src_26000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_26000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_26000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_26000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS paid_at__extract_doy + , bookings_source_src_26000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_26000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_26000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_26000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_26000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_26000.listing_id AS listing + , bookings_source_src_26000.guest_id AS guest + , bookings_source_src_26000.host_id AS host + , bookings_source_src_26000.guest_id AS user + , bookings_source_src_26000.listing_id AS booking__listing + , bookings_source_src_26000.guest_id AS booking__guest + , bookings_source_src_26000.host_id AS booking__host + , bookings_source_src_26000.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_26000 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Read From SemanticModelDataSet('listings') + -- Pass Only Elements: ['capacity', 'window_start__day', 'window_end__day', 'listing'] + SELECT + listings_src_26000.active_from AS window_start__day + , listings_src_26000.active_to AS window_end__day + , listings_src_26000.capacity + , listings_src_26000.listing_id AS listing + FROM ***************************.dim_listings listings_src_26000 + ) subq_2 + ON + ( + subq_1.listing = subq_2.listing + ) AND ( + ( + subq_1.metric_time__day >= subq_2.window_start__day + ) AND ( ( - subq_2.listing = subq_4.listing - ) AND ( - ( - subq_2.metric_time__day >= subq_4.window_start__day - ) AND ( - ( - subq_2.metric_time__day < subq_4.window_end__day - ) OR ( - subq_4.window_end__day IS NULL - ) - ) + subq_1.metric_time__day < subq_2.window_end__day + ) OR ( + subq_2.window_end__day IS NULL ) - ) subq_5 - ) subq_6 - WHERE listing__capacity > 2 - ) subq_7 - ) subq_8 + ) + ) + ) subq_3 + WHERE listing__capacity > 2 + ) subq_4 GROUP BY - subq_8.metric_time__day -) subq_9 + subq_4.metric_time__day +) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0_optimized.sql index 8f567bda9a..0d00891bd7 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_join_to_scd_dimension__plan0_optimized.sql @@ -9,9 +9,8 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__capacity', 'metric_time__day'] SELECT - subq_12.metric_time__day AS metric_time__day - , listings_src_26000.capacity AS listing__capacity - , subq_12.bookings AS bookings + subq_7.metric_time__day AS metric_time__day + , subq_7.bookings AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -21,24 +20,24 @@ FROM ( , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_26000 - ) subq_12 + ) subq_7 LEFT OUTER JOIN ***************************.dim_listings listings_src_26000 ON ( - subq_12.listing = listings_src_26000.listing_id + subq_7.listing = listings_src_26000.listing_id ) AND ( ( - subq_12.metric_time__day >= listings_src_26000.active_from + subq_7.metric_time__day >= listings_src_26000.active_from ) AND ( ( - subq_12.metric_time__day < listings_src_26000.active_to + subq_7.metric_time__day < listings_src_26000.active_to ) OR ( listings_src_26000.active_to IS NULL ) ) ) -) subq_16 +) subq_9 WHERE listing__capacity > 2 GROUP BY metric_time__day diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_limit_rows__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_limit_rows__plan0.sql index 9054804d3a..5dd3879fc9 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_limit_rows__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_limit_rows__plan0.sql @@ -1,220 +1,119 @@ -- Order By [] Limit 1 SELECT - subq_4.ds__day - , subq_4.bookings + subq_3.ds__day + , subq_3.bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_3.ds__day - , subq_3.bookings + subq_2.ds__day + , subq_2.bookings FROM ( -- Aggregate Measures SELECT - subq_2.ds__day - , SUM(subq_2.bookings) AS bookings + subq_1.ds__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'ds__day'] SELECT - subq_1.ds__day - , subq_1.bookings + subq_0.ds__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.ds__day - ) subq_3 -) subq_4 + subq_1.ds__day + ) subq_2 +) subq_3 LIMIT 1 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_limit_rows__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_limit_rows__plan0_optimized.sql index 145b088778..52f987761b 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_limit_rows__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_limit_rows__plan0_optimized.sql @@ -12,7 +12,7 @@ FROM ( DATE_TRUNC('day', ds) AS ds__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_7 +) subq_5 GROUP BY ds__day LIMIT 1 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_local_dimension_using_local_entity__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_local_dimension_using_local_entity__plan0.sql index 81a14bcb3f..2f165e21cd 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_local_dimension_using_local_entity__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_local_dimension_using_local_entity__plan0.sql @@ -1,150 +1,80 @@ -- Compute Metrics via Expressions SELECT - subq_3.listing__country_latest - , subq_3.listings + subq_2.listing__country_latest + , subq_2.listings FROM ( -- Aggregate Measures SELECT - subq_2.listing__country_latest - , SUM(subq_2.listings) AS listings + subq_1.listing__country_latest + , SUM(subq_1.listings) AS listings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['listings', 'listing__country_latest'] SELECT - subq_1.listing__country_latest - , subq_1.listings + subq_0.listing__country_latest + , subq_0.listings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.created_at__day - , subq_0.created_at__week - , subq_0.created_at__month - , subq_0.created_at__quarter - , subq_0.created_at__year - , subq_0.created_at__extract_year - , subq_0.created_at__extract_quarter - , subq_0.created_at__extract_month - , subq_0.created_at__extract_day - , subq_0.created_at__extract_dow - , subq_0.created_at__extract_doy - , subq_0.listing__ds__day - , subq_0.listing__ds__week - , subq_0.listing__ds__month - , subq_0.listing__ds__quarter - , subq_0.listing__ds__year - , subq_0.listing__ds__extract_year - , subq_0.listing__ds__extract_quarter - , subq_0.listing__ds__extract_month - , subq_0.listing__ds__extract_day - , subq_0.listing__ds__extract_dow - , subq_0.listing__ds__extract_doy - , subq_0.listing__created_at__day - , subq_0.listing__created_at__week - , subq_0.listing__created_at__month - , subq_0.listing__created_at__quarter - , subq_0.listing__created_at__year - , subq_0.listing__created_at__extract_year - , subq_0.listing__created_at__extract_quarter - , subq_0.listing__created_at__extract_month - , subq_0.listing__created_at__extract_day - , subq_0.listing__created_at__extract_dow - , subq_0.listing__created_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 - , subq_0.user - , subq_0.listing__user - , subq_0.country_latest - , subq_0.is_lux_latest - , subq_0.capacity_latest - , subq_0.listing__country_latest - , subq_0.listing__is_lux_latest - , subq_0.listing__capacity_latest - , subq_0.listings - , subq_0.largest_listing - , subq_0.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 - ) subq_1 - ) subq_2 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_0 + ) subq_1 GROUP BY - subq_2.listing__country_latest -) subq_3 + subq_1.listing__country_latest +) subq_2 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_local_dimension_using_local_entity__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_local_dimension_using_local_entity__plan0_optimized.sql index 5d5e3407c2..4e2b9249fb 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_local_dimension_using_local_entity__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_local_dimension_using_local_entity__plan0_optimized.sql @@ -11,6 +11,6 @@ FROM ( country AS listing__country_latest , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_6 +) subq_4 GROUP BY listing__country_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0.sql index 0c1c45d416..d316b74635 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0.sql @@ -1,1003 +1,532 @@ -- Compute Metrics via Expressions SELECT - subq_29.metric_time__day + subq_20.metric_time__day , average_booking_value * bookings / NULLIF(booking_value, 0) AS lux_booking_value_rate_expr FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_11.metric_time__day, subq_23.metric_time__day, subq_28.metric_time__day) AS metric_time__day - , MAX(subq_11.average_booking_value) AS average_booking_value - , MAX(subq_23.bookings) AS bookings - , MAX(subq_28.booking_value) AS booking_value + COALESCE(subq_7.metric_time__day, subq_15.metric_time__day, subq_19.metric_time__day) AS metric_time__day + , MAX(subq_7.average_booking_value) AS average_booking_value + , MAX(subq_15.bookings) AS bookings + , MAX(subq_19.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.average_booking_value + subq_6.metric_time__day + , subq_6.average_booking_value FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , AVG(subq_9.average_booking_value) AS average_booking_value + subq_5.metric_time__day + , AVG(subq_5.average_booking_value) AS average_booking_value FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.average_booking_value + subq_4.metric_time__day + , subq_4.average_booking_value FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_7.metric_time__day - , subq_7.listing__is_lux_latest - , subq_7.average_booking_value + subq_1.metric_time__day AS metric_time__day + , subq_1.average_booking_value AS average_booking_value FROM ( - -- Pass Only Elements: ['average_booking_value', 'listing__is_lux_latest', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['average_booking_value', 'metric_time__day', 'listing'] SELECT - subq_6.metric_time__day - , subq_6.listing__is_lux_latest - , subq_6.average_booking_value + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.average_booking_value FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_2.metric_time__day AS metric_time__day - , subq_2.listing AS listing - , subq_5.is_lux_latest AS listing__is_lux_latest - , subq_2.average_booking_value AS average_booking_value - FROM ( - -- Pass Only Elements: ['average_booking_value', 'metric_time__day', 'listing'] - SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.average_booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['is_lux_latest', 'listing'] - SELECT - subq_4.listing - , subq_4.is_lux_latest - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.listing__ds__day - , subq_3.listing__ds__week - , subq_3.listing__ds__month - , subq_3.listing__ds__quarter - , subq_3.listing__ds__year - , subq_3.listing__ds__extract_year - , subq_3.listing__ds__extract_quarter - , subq_3.listing__ds__extract_month - , subq_3.listing__ds__extract_day - , subq_3.listing__ds__extract_dow - , subq_3.listing__ds__extract_doy - , subq_3.listing__created_at__day - , subq_3.listing__created_at__week - , subq_3.listing__created_at__month - , subq_3.listing__created_at__quarter - , subq_3.listing__created_at__year - , subq_3.listing__created_at__extract_year - , subq_3.listing__created_at__extract_quarter - , subq_3.listing__created_at__extract_month - , subq_3.listing__created_at__extract_day - , subq_3.listing__created_at__extract_dow - , subq_3.listing__created_at__extract_doy - , subq_3.ds__day AS metric_time__day - , subq_3.ds__week AS metric_time__week - , subq_3.ds__month AS metric_time__month - , subq_3.ds__quarter AS metric_time__quarter - , subq_3.ds__year AS metric_time__year - , subq_3.ds__extract_year AS metric_time__extract_year - , subq_3.ds__extract_quarter AS metric_time__extract_quarter - , subq_3.ds__extract_month AS metric_time__extract_month - , subq_3.ds__extract_day AS metric_time__extract_day - , subq_3.ds__extract_dow AS metric_time__extract_dow - , subq_3.ds__extract_doy AS metric_time__extract_doy - , subq_3.listing - , subq_3.user - , subq_3.listing__user - , subq_3.country_latest - , subq_3.is_lux_latest - , subq_3.capacity_latest - , subq_3.listing__country_latest - , subq_3.listing__is_lux_latest - , subq_3.listing__capacity_latest - , subq_3.listings - , subq_3.largest_listing - , subq_3.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_3 - ) subq_4 - ) subq_5 - ON - subq_2.listing = subq_5.listing - ) subq_6 - ) subq_7 - WHERE listing__is_lux_latest - ) subq_8 - ) subq_9 + 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 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['is_lux_latest', 'listing'] + SELECT + subq_2.listing + , subq_2.is_lux_latest + FROM ( + -- Read Elements From Semantic Model 'listings_latest' + SELECT + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_2 + ) subq_3 + ON + subq_1.listing = subq_3.listing + ) subq_4 + WHERE listing__is_lux_latest + ) subq_5 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_5.metric_time__day + ) subq_6 + ) subq_7 FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_22.metric_time__day - , subq_22.bookings + subq_14.metric_time__day + , subq_14.bookings FROM ( -- Aggregate Measures SELECT - subq_21.metric_time__day - , SUM(subq_21.bookings) AS bookings + subq_13.metric_time__day + , SUM(subq_13.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_20.metric_time__day - , subq_20.bookings + subq_12.metric_time__day + , subq_12.bookings FROM ( - -- Constrain Output with WHERE + -- Join Standard Outputs + -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_19.metric_time__day - , subq_19.listing__is_lux_latest - , subq_19.bookings + subq_9.metric_time__day AS metric_time__day + , subq_9.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'listing__is_lux_latest', 'metric_time__day'] + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] + SELECT + subq_8.ds__day AS metric_time__day + , subq_8.listing + , subq_8.bookings + 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_8 + ) subq_9 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['is_lux_latest', 'listing'] SELECT - subq_18.metric_time__day - , subq_18.listing__is_lux_latest - , subq_18.bookings + subq_10.listing + , subq_10.is_lux_latest FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_14.metric_time__day AS metric_time__day - , subq_14.listing AS listing - , subq_17.is_lux_latest AS listing__is_lux_latest - , subq_14.bookings AS bookings - FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] - SELECT - subq_13.metric_time__day - , subq_13.listing - , subq_13.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - 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_partitioned__day - , subq_12.ds_partitioned__week - , subq_12.ds_partitioned__month - , subq_12.ds_partitioned__quarter - , subq_12.ds_partitioned__year - , subq_12.ds_partitioned__extract_year - , subq_12.ds_partitioned__extract_quarter - , subq_12.ds_partitioned__extract_month - , subq_12.ds_partitioned__extract_day - , subq_12.ds_partitioned__extract_dow - , subq_12.ds_partitioned__extract_doy - , subq_12.paid_at__day - , subq_12.paid_at__week - , subq_12.paid_at__month - , subq_12.paid_at__quarter - , subq_12.paid_at__year - , subq_12.paid_at__extract_year - , subq_12.paid_at__extract_quarter - , subq_12.paid_at__extract_month - , subq_12.paid_at__extract_day - , subq_12.paid_at__extract_dow - , subq_12.paid_at__extract_doy - , subq_12.booking__ds__day - , subq_12.booking__ds__week - , subq_12.booking__ds__month - , subq_12.booking__ds__quarter - , subq_12.booking__ds__year - , subq_12.booking__ds__extract_year - , subq_12.booking__ds__extract_quarter - , subq_12.booking__ds__extract_month - , subq_12.booking__ds__extract_day - , subq_12.booking__ds__extract_dow - , subq_12.booking__ds__extract_doy - , subq_12.booking__ds_partitioned__day - , subq_12.booking__ds_partitioned__week - , subq_12.booking__ds_partitioned__month - , subq_12.booking__ds_partitioned__quarter - , subq_12.booking__ds_partitioned__year - , subq_12.booking__ds_partitioned__extract_year - , subq_12.booking__ds_partitioned__extract_quarter - , subq_12.booking__ds_partitioned__extract_month - , subq_12.booking__ds_partitioned__extract_day - , subq_12.booking__ds_partitioned__extract_dow - , subq_12.booking__ds_partitioned__extract_doy - , subq_12.booking__paid_at__day - , subq_12.booking__paid_at__week - , subq_12.booking__paid_at__month - , subq_12.booking__paid_at__quarter - , subq_12.booking__paid_at__year - , subq_12.booking__paid_at__extract_year - , subq_12.booking__paid_at__extract_quarter - , subq_12.booking__paid_at__extract_month - , subq_12.booking__paid_at__extract_day - , subq_12.booking__paid_at__extract_dow - , subq_12.booking__paid_at__extract_doy - , subq_12.ds__day AS metric_time__day - , subq_12.ds__week AS metric_time__week - , subq_12.ds__month AS metric_time__month - , subq_12.ds__quarter AS metric_time__quarter - , subq_12.ds__year AS metric_time__year - , subq_12.ds__extract_year AS metric_time__extract_year - , subq_12.ds__extract_quarter AS metric_time__extract_quarter - , subq_12.ds__extract_month AS metric_time__extract_month - , subq_12.ds__extract_day AS metric_time__extract_day - , subq_12.ds__extract_dow AS metric_time__extract_dow - , subq_12.ds__extract_doy AS metric_time__extract_doy - , subq_12.listing - , subq_12.guest - , subq_12.host - , subq_12.booking__listing - , subq_12.booking__guest - , subq_12.booking__host - , subq_12.is_instant - , subq_12.booking__is_instant - , subq_12.bookings - , subq_12.instant_bookings - , subq_12.booking_value - , subq_12.max_booking_value - , subq_12.min_booking_value - , subq_12.bookers - , subq_12.average_booking_value - , subq_12.referred_bookings - , subq_12.median_booking_value - , subq_12.booking_value_p99 - , subq_12.discrete_booking_value_p99 - , subq_12.approximate_continuous_booking_value_p99 - , subq_12.approximate_discrete_booking_value_p99 - 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_12 - ) subq_13 - ) subq_14 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['is_lux_latest', 'listing'] - SELECT - subq_16.listing - , subq_16.is_lux_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 - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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 - ON - subq_14.listing = subq_17.listing - ) subq_18 - ) subq_19 - WHERE listing__is_lux_latest - ) subq_20 - ) subq_21 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_10 + ) subq_11 + ON + subq_9.listing = subq_11.listing + ) subq_12 + WHERE listing__is_lux_latest + ) subq_13 GROUP BY - subq_21.metric_time__day - ) subq_22 - ) subq_23 + subq_13.metric_time__day + ) subq_14 + ) subq_15 ON - subq_11.metric_time__day = subq_23.metric_time__day + subq_7.metric_time__day = subq_15.metric_time__day FULL OUTER JOIN ( -- Compute Metrics via Expressions SELECT - subq_27.metric_time__day - , subq_27.booking_value + subq_18.metric_time__day + , subq_18.booking_value FROM ( -- Aggregate Measures SELECT - subq_26.metric_time__day - , SUM(subq_26.booking_value) AS booking_value + subq_17.metric_time__day + , SUM(subq_17.booking_value) AS booking_value FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_25.metric_time__day - , subq_25.booking_value + subq_16.ds__day AS metric_time__day + , subq_16.booking_value FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_24.ds__day - , subq_24.ds__week - , subq_24.ds__month - , subq_24.ds__quarter - , subq_24.ds__year - , subq_24.ds__extract_year - , subq_24.ds__extract_quarter - , subq_24.ds__extract_month - , subq_24.ds__extract_day - , subq_24.ds__extract_dow - , subq_24.ds__extract_doy - , subq_24.ds_partitioned__day - , subq_24.ds_partitioned__week - , subq_24.ds_partitioned__month - , subq_24.ds_partitioned__quarter - , subq_24.ds_partitioned__year - , subq_24.ds_partitioned__extract_year - , subq_24.ds_partitioned__extract_quarter - , subq_24.ds_partitioned__extract_month - , subq_24.ds_partitioned__extract_day - , subq_24.ds_partitioned__extract_dow - , subq_24.ds_partitioned__extract_doy - , subq_24.paid_at__day - , subq_24.paid_at__week - , subq_24.paid_at__month - , subq_24.paid_at__quarter - , subq_24.paid_at__year - , subq_24.paid_at__extract_year - , subq_24.paid_at__extract_quarter - , subq_24.paid_at__extract_month - , subq_24.paid_at__extract_day - , subq_24.paid_at__extract_dow - , subq_24.paid_at__extract_doy - , subq_24.booking__ds__day - , subq_24.booking__ds__week - , subq_24.booking__ds__month - , subq_24.booking__ds__quarter - , subq_24.booking__ds__year - , subq_24.booking__ds__extract_year - , subq_24.booking__ds__extract_quarter - , subq_24.booking__ds__extract_month - , subq_24.booking__ds__extract_day - , subq_24.booking__ds__extract_dow - , subq_24.booking__ds__extract_doy - , subq_24.booking__ds_partitioned__day - , subq_24.booking__ds_partitioned__week - , subq_24.booking__ds_partitioned__month - , subq_24.booking__ds_partitioned__quarter - , subq_24.booking__ds_partitioned__year - , subq_24.booking__ds_partitioned__extract_year - , subq_24.booking__ds_partitioned__extract_quarter - , subq_24.booking__ds_partitioned__extract_month - , subq_24.booking__ds_partitioned__extract_day - , subq_24.booking__ds_partitioned__extract_dow - , subq_24.booking__ds_partitioned__extract_doy - , subq_24.booking__paid_at__day - , subq_24.booking__paid_at__week - , subq_24.booking__paid_at__month - , subq_24.booking__paid_at__quarter - , subq_24.booking__paid_at__year - , subq_24.booking__paid_at__extract_year - , subq_24.booking__paid_at__extract_quarter - , subq_24.booking__paid_at__extract_month - , subq_24.booking__paid_at__extract_day - , subq_24.booking__paid_at__extract_dow - , subq_24.booking__paid_at__extract_doy - , subq_24.ds__day AS metric_time__day - , subq_24.ds__week AS metric_time__week - , subq_24.ds__month AS metric_time__month - , subq_24.ds__quarter AS metric_time__quarter - , subq_24.ds__year AS metric_time__year - , subq_24.ds__extract_year AS metric_time__extract_year - , subq_24.ds__extract_quarter AS metric_time__extract_quarter - , subq_24.ds__extract_month AS metric_time__extract_month - , subq_24.ds__extract_day AS metric_time__extract_day - , subq_24.ds__extract_dow AS metric_time__extract_dow - , subq_24.ds__extract_doy AS metric_time__extract_doy - , subq_24.listing - , subq_24.guest - , subq_24.host - , subq_24.booking__listing - , subq_24.booking__guest - , subq_24.booking__host - , subq_24.is_instant - , subq_24.booking__is_instant - , subq_24.bookings - , subq_24.instant_bookings - , subq_24.booking_value - , subq_24.max_booking_value - , subq_24.min_booking_value - , subq_24.bookers - , subq_24.average_booking_value - , subq_24.referred_bookings - , subq_24.median_booking_value - , subq_24.booking_value_p99 - , subq_24.discrete_booking_value_p99 - , subq_24.approximate_continuous_booking_value_p99 - , subq_24.approximate_discrete_booking_value_p99 - 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_24 - ) subq_25 - ) subq_26 + 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_16 + ) subq_17 GROUP BY - subq_26.metric_time__day - ) subq_27 - ) subq_28 + subq_17.metric_time__day + ) subq_18 + ) subq_19 ON - COALESCE(subq_11.metric_time__day, subq_23.metric_time__day) = subq_28.metric_time__day + COALESCE(subq_7.metric_time__day, subq_15.metric_time__day) = subq_19.metric_time__day GROUP BY - COALESCE(subq_11.metric_time__day, subq_23.metric_time__day, subq_28.metric_time__day) -) subq_29 + COALESCE(subq_7.metric_time__day, subq_15.metric_time__day, subq_19.metric_time__day) +) subq_20 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0_optimized.sql index 3b5d6bfe50..18312b1611 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint__plan0_optimized.sql @@ -5,10 +5,10 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_41.metric_time__day, subq_46.metric_time__day) AS metric_time__day - , MAX(subq_41.average_booking_value) AS average_booking_value - , MAX(subq_41.bookings) AS bookings - , MAX(subq_46.booking_value) AS booking_value + COALESCE(subq_28.metric_time__day, subq_32.metric_time__day) AS metric_time__day + , MAX(subq_28.average_booking_value) AS average_booking_value + , MAX(subq_28.bookings) AS bookings + , MAX(subq_32.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['average_booking_value', 'bookings', 'metric_time__day'] @@ -22,10 +22,9 @@ FROM ( -- Join Standard Outputs -- Pass Only Elements: ['average_booking_value', 'bookings', 'listing__is_lux_latest', 'metric_time__day'] SELECT - subq_32.metric_time__day AS metric_time__day - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , subq_32.bookings AS bookings - , subq_32.average_booking_value AS average_booking_value + subq_22.metric_time__day AS metric_time__day + , subq_22.bookings AS bookings + , subq_22.average_booking_value AS average_booking_value FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -36,16 +35,16 @@ FROM ( , 1 AS bookings , booking_value AS average_booking_value FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_32 + ) subq_22 LEFT OUTER JOIN ***************************.dim_listings_latest listings_latest_src_28000 ON - subq_32.listing = listings_latest_src_28000.listing_id - ) subq_37 + subq_22.listing = listings_latest_src_28000.listing_id + ) subq_25 WHERE listing__is_lux_latest GROUP BY metric_time__day - ) subq_41 + ) subq_28 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -58,9 +57,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_46 + ) subq_32 ON - subq_41.metric_time__day = subq_46.metric_time__day + subq_28.metric_time__day = subq_32.metric_time__day GROUP BY - COALESCE(subq_41.metric_time__day, subq_46.metric_time__day) -) subq_47 + COALESCE(subq_28.metric_time__day, subq_32.metric_time__day) +) subq_33 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql index b2323d92df..e819abaaff 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0.sql @@ -1,359 +1,36 @@ -- Compute Metrics via Expressions SELECT - subq_12.metric_time__day - , CAST(subq_12.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_12.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio + subq_9.metric_time__day + , CAST(subq_9.booking_value_with_is_instant_constraint AS DOUBLE) / CAST(NULLIF(subq_9.booking_value, 0) AS DOUBLE) AS instant_booking_value_ratio FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) AS metric_time__day - , MAX(subq_6.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_11.booking_value) AS booking_value + COALESCE(subq_4.metric_time__day, subq_8.metric_time__day) AS metric_time__day + , MAX(subq_4.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_8.booking_value) AS booking_value FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.booking_value AS booking_value_with_is_instant_constraint + subq_3.metric_time__day + , subq_3.booking_value AS booking_value_with_is_instant_constraint FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.booking_value) AS booking_value + subq_2.metric_time__day + , SUM(subq_2.booking_value) AS booking_value FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.booking_value - FROM ( - -- Constrain Output with WHERE - SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.booking_value - FROM ( - -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] - SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.booking_value - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - WHERE booking__is_instant - ) subq_3 - ) subq_4 - GROUP BY - subq_4.metric_time__day - ) subq_5 - ) subq_6 - FULL OUTER JOIN ( - -- Compute Metrics via Expressions - SELECT - subq_10.metric_time__day - , subq_10.booking_value - FROM ( - -- Aggregate Measures - SELECT - subq_9.metric_time__day - , SUM(subq_9.booking_value) AS booking_value - FROM ( - -- Pass Only Elements: ['booking_value', 'metric_time__day'] - SELECT - subq_8.metric_time__day - , subq_8.booking_value + subq_1.metric_time__day + , subq_1.booking_value FROM ( -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['booking_value', 'booking__is_instant', 'metric_time__day'] 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.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.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.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_0.ds__day AS metric_time__day + , subq_0.booking__is_instant + , subq_0.booking_value FROM ( -- Read Elements From Semantic Model 'bookings_source' SELECT @@ -446,15 +123,130 @@ 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_7 - ) subq_8 - ) subq_9 + ) subq_0 + ) subq_1 + WHERE booking__is_instant + ) subq_2 + GROUP BY + subq_2.metric_time__day + ) subq_3 + ) subq_4 + FULL OUTER JOIN ( + -- Compute Metrics via Expressions + SELECT + subq_7.metric_time__day + , subq_7.booking_value + FROM ( + -- Aggregate Measures + SELECT + subq_6.metric_time__day + , SUM(subq_6.booking_value) AS booking_value + FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['booking_value', 'metric_time__day'] + SELECT + subq_5.ds__day AS metric_time__day + , subq_5.booking_value + 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_5 + ) subq_6 GROUP BY - subq_9.metric_time__day - ) subq_10 - ) subq_11 + subq_6.metric_time__day + ) subq_7 + ) subq_8 ON - subq_6.metric_time__day = subq_11.metric_time__day + subq_4.metric_time__day = subq_8.metric_time__day GROUP BY - COALESCE(subq_6.metric_time__day, subq_11.metric_time__day) -) subq_12 + COALESCE(subq_4.metric_time__day, subq_8.metric_time__day) +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql index a465dac6f6..3804711f9b 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_reused_measure__plan0_optimized.sql @@ -5,9 +5,9 @@ SELECT FROM ( -- Combine Aggregated Outputs SELECT - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) AS metric_time__day - , MAX(subq_19.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint - , MAX(subq_24.booking_value) AS booking_value + COALESCE(subq_14.metric_time__day, subq_18.metric_time__day) AS metric_time__day + , MAX(subq_14.booking_value_with_is_instant_constraint) AS booking_value_with_is_instant_constraint + , MAX(subq_18.booking_value) AS booking_value FROM ( -- Constrain Output with WHERE -- Pass Only Elements: ['booking_value', 'metric_time__day'] @@ -25,11 +25,11 @@ FROM ( , is_instant AS booking__is_instant , booking_value FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_15 + ) subq_11 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_19 + ) subq_14 FULL OUTER JOIN ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -42,9 +42,9 @@ FROM ( FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', ds) - ) subq_24 + ) subq_18 ON - subq_19.metric_time__day = subq_24.metric_time__day + subq_14.metric_time__day = subq_18.metric_time__day GROUP BY - COALESCE(subq_19.metric_time__day, subq_24.metric_time__day) -) subq_25 + COALESCE(subq_14.metric_time__day, subq_18.metric_time__day) +) subq_19 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0.sql index 9182b35971..c1420cd08d 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0.sql @@ -1,234 +1,127 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day + subq_4.metric_time__day , delayed_bookings * 2 AS double_counted_delayed_bookings FROM ( -- Compute Metrics via Expressions SELECT - subq_5.metric_time__day - , subq_5.bookings AS delayed_bookings + subq_3.metric_time__day + , subq_3.bookings AS delayed_bookings FROM ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_1.metric_time__day + , subq_1.bookings FROM ( - -- Constrain Output with WHERE + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_0.ds__day AS metric_time__day + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - WHERE NOT booking__is_instant - ) subq_3 - ) subq_4 + 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 + ) subq_1 + WHERE NOT booking__is_instant + ) subq_2 GROUP BY - subq_4.metric_time__day - ) subq_5 -) subq_6 + subq_2.metric_time__day + ) subq_3 +) subq_4 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql index 3202b9915d..466a903835 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_measure_constraint_with_single_expr_and_alias__plan0_optimized.sql @@ -19,8 +19,8 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_9 + ) subq_6 WHERE NOT booking__is_instant GROUP BY metric_time__day -) subq_13 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql index 30b8ce6b61..469fe3a9f0 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0.sql @@ -1,366 +1,195 @@ -- Compute Metrics via Expressions SELECT - CAST(subq_10.bookings AS DOUBLE) / CAST(NULLIF(subq_10.listings, 0) AS DOUBLE) AS bookings_per_listing + CAST(subq_8.bookings AS DOUBLE) / CAST(NULLIF(subq_8.listings, 0) AS DOUBLE) AS bookings_per_listing FROM ( -- Combine Aggregated Outputs SELECT - MAX(subq_4.bookings) AS bookings - , MAX(subq_9.listings) AS listings + MAX(subq_3.bookings) AS bookings + , MAX(subq_7.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT - subq_3.bookings + subq_2.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_2.bookings) AS bookings + SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings',] SELECT - subq_1.bookings + subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - ) subq_3 - ) subq_4 + 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 + ) subq_1 + ) subq_2 + ) subq_3 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_8.listings + subq_6.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_7.listings) AS listings + SUM(subq_5.listings) AS listings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['listings',] SELECT - subq_6.listings + subq_4.listings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_5.ds__day - , subq_5.ds__week - , subq_5.ds__month - , subq_5.ds__quarter - , subq_5.ds__year - , subq_5.ds__extract_year - , subq_5.ds__extract_quarter - , subq_5.ds__extract_month - , subq_5.ds__extract_day - , subq_5.ds__extract_dow - , subq_5.ds__extract_doy - , subq_5.created_at__day - , subq_5.created_at__week - , subq_5.created_at__month - , subq_5.created_at__quarter - , subq_5.created_at__year - , subq_5.created_at__extract_year - , subq_5.created_at__extract_quarter - , subq_5.created_at__extract_month - , subq_5.created_at__extract_day - , subq_5.created_at__extract_dow - , subq_5.created_at__extract_doy - , subq_5.listing__ds__day - , subq_5.listing__ds__week - , subq_5.listing__ds__month - , subq_5.listing__ds__quarter - , subq_5.listing__ds__year - , subq_5.listing__ds__extract_year - , subq_5.listing__ds__extract_quarter - , subq_5.listing__ds__extract_month - , subq_5.listing__ds__extract_day - , subq_5.listing__ds__extract_dow - , subq_5.listing__ds__extract_doy - , subq_5.listing__created_at__day - , subq_5.listing__created_at__week - , subq_5.listing__created_at__month - , subq_5.listing__created_at__quarter - , subq_5.listing__created_at__year - , subq_5.listing__created_at__extract_year - , subq_5.listing__created_at__extract_quarter - , subq_5.listing__created_at__extract_month - , subq_5.listing__created_at__extract_day - , subq_5.listing__created_at__extract_dow - , subq_5.listing__created_at__extract_doy - , subq_5.ds__day AS metric_time__day - , subq_5.ds__week AS metric_time__week - , subq_5.ds__month AS metric_time__month - , subq_5.ds__quarter AS metric_time__quarter - , subq_5.ds__year AS metric_time__year - , subq_5.ds__extract_year AS metric_time__extract_year - , subq_5.ds__extract_quarter AS metric_time__extract_quarter - , subq_5.ds__extract_month AS metric_time__extract_month - , subq_5.ds__extract_day AS metric_time__extract_day - , subq_5.ds__extract_dow AS metric_time__extract_dow - , subq_5.ds__extract_doy AS metric_time__extract_doy - , subq_5.listing - , subq_5.user - , subq_5.listing__user - , subq_5.country_latest - , subq_5.is_lux_latest - , subq_5.capacity_latest - , subq_5.listing__country_latest - , subq_5.listing__is_lux_latest - , subq_5.listing__capacity_latest - , subq_5.listings - , subq_5.largest_listing - , subq_5.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_5 - ) subq_6 - ) subq_7 - ) subq_8 - ) subq_9 -) subq_10 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_4 + ) subq_5 + ) subq_6 + ) subq_7 +) subq_8 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql index 9137e238b0..64818cc2ae 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_metric_with_measures_from_multiple_sources_no_dimensions__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Combine Aggregated Outputs -- Compute Metrics via Expressions SELECT - CAST(MAX(subq_15.bookings) AS DOUBLE) / CAST(NULLIF(MAX(subq_20.listings), 0) AS DOUBLE) AS bookings_per_listing + CAST(MAX(subq_12.bookings) AS DOUBLE) / CAST(NULLIF(MAX(subq_16.listings), 0) AS DOUBLE) AS bookings_per_listing FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -11,7 +11,7 @@ FROM ( SELECT SUM(1) AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 -) subq_15 +) subq_12 CROSS JOIN ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -21,4 +21,4 @@ CROSS JOIN ( SELECT SUM(1) AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 -) subq_20 +) subq_16 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time__plan0.sql index 375cb5e89e..75d1b39fe2 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time__plan0.sql @@ -1,56 +1,29 @@ -- Calculate min and max SELECT - MIN(subq_2.metric_time__day) AS metric_time__day__min - , MAX(subq_2.metric_time__day) AS metric_time__day__max + MIN(subq_1.metric_time__day) AS metric_time__day__min + , MAX(subq_1.metric_time__day) AS metric_time__day__max FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__day',] SELECT - subq_1.metric_time__day + subq_0.ds__day AS metric_time__day FROM ( - -- Metric Time Dimension 'ds' + -- Time Spine SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds__martian_day - , 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.ds__martian_day AS metric_time__martian_day - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day - , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week - , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month - , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter - , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year - , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year - , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter - , EXTRACT(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_0 - ) subq_1 + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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_0 GROUP BY - subq_1.metric_time__day -) subq_2 + subq_0.ds__day +) subq_1 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time__plan0_optimized.sql index 4d31ef04b9..b958a92c02 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time__plan0_optimized.sql @@ -11,4 +11,4 @@ FROM ( FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY DATE_TRUNC('day', ds) -) subq_5 +) subq_3 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time_week__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time_week__plan0.sql index 086649cf24..5318f801e9 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time_week__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time_week__plan0.sql @@ -1,56 +1,29 @@ -- Calculate min and max SELECT - MIN(subq_2.metric_time__week) AS metric_time__week__min - , MAX(subq_2.metric_time__week) AS metric_time__week__max + MIN(subq_1.metric_time__week) AS metric_time__week__min + , MAX(subq_1.metric_time__week) AS metric_time__week__max FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['metric_time__week',] SELECT - subq_1.metric_time__week + subq_0.ds__week AS metric_time__week FROM ( - -- Metric Time Dimension 'ds' + -- Time Spine SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds__martian_day - , 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.ds__martian_day AS metric_time__martian_day - FROM ( - -- Time Spine - SELECT - DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day - , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week - , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month - , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter - , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year - , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year - , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter - , EXTRACT(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_0 - ) subq_1 + DATE_TRUNC('day', time_spine_src_28006.ds) AS ds__day + , DATE_TRUNC('week', time_spine_src_28006.ds) AS ds__week + , DATE_TRUNC('month', time_spine_src_28006.ds) AS ds__month + , DATE_TRUNC('quarter', time_spine_src_28006.ds) AS ds__quarter + , DATE_TRUNC('year', time_spine_src_28006.ds) AS ds__year + , EXTRACT(year FROM time_spine_src_28006.ds) AS ds__extract_year + , EXTRACT(quarter FROM time_spine_src_28006.ds) AS ds__extract_quarter + , EXTRACT(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_0 GROUP BY - subq_1.metric_time__week -) subq_2 + subq_0.ds__week +) subq_1 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time_week__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time_week__plan0_optimized.sql index 4ceb83d067..6dccaa4c5f 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time_week__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_metric_time_week__plan0_optimized.sql @@ -11,4 +11,4 @@ FROM ( FROM ***************************.mf_time_spine time_spine_src_28006 GROUP BY DATE_TRUNC('week', ds) -) subq_5 +) subq_3 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_categorical__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_categorical__plan0.sql index c8c44e9886..0f2144188c 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_categorical__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_categorical__plan0.sql @@ -1,72 +1,13 @@ -- Calculate min and max SELECT - MIN(subq_1.listing__country_latest) AS listing__country_latest__min - , MAX(subq_1.listing__country_latest) AS listing__country_latest__max + MIN(subq_0.listing__country_latest) AS listing__country_latest__min + , MAX(subq_0.listing__country_latest) AS listing__country_latest__max FROM ( + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['listing__country_latest',] SELECT - subq_0.listing__country_latest - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_0 + listings_latest_src_28000.country AS listing__country_latest + FROM ***************************.dim_listings_latest listings_latest_src_28000 GROUP BY - subq_0.listing__country_latest -) subq_1 + listings_latest_src_28000.country +) subq_0 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_categorical__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_categorical__plan0_optimized.sql index a8d1afa6a8..2ef26db75e 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_categorical__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_categorical__plan0_optimized.sql @@ -3,11 +3,11 @@ SELECT MIN(listing__country_latest) AS listing__country_latest__min , MAX(listing__country_latest) AS listing__country_latest__max FROM ( - -- Read Elements From Semantic Model 'listings_latest' + -- Read From SemanticModelDataSet('listings_latest') -- Pass Only Elements: ['listing__country_latest',] SELECT country AS listing__country_latest FROM ***************************.dim_listings_latest listings_latest_src_28000 GROUP BY country -) subq_3 +) subq_1 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time__plan0.sql index 0675d4b77f..2bc7407e97 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time__plan0.sql @@ -1,104 +1,13 @@ -- Calculate min and max SELECT - MIN(subq_1.booking__paid_at__day) AS booking__paid_at__day__min - , MAX(subq_1.booking__paid_at__day) AS booking__paid_at__day__max + MIN(subq_0.booking__paid_at__day) AS booking__paid_at__day__min + , MAX(subq_0.booking__paid_at__day) AS booking__paid_at__day__max FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['booking__paid_at__day',] SELECT - subq_0.booking__paid_at__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 + DATE_TRUNC('day', bookings_source_src_28000.paid_at) AS booking__paid_at__day + FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY - subq_0.booking__paid_at__day -) subq_1 + DATE_TRUNC('day', bookings_source_src_28000.paid_at) +) subq_0 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time__plan0_optimized.sql index e6a861c58f..b6229ce8c6 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time__plan0_optimized.sql @@ -3,11 +3,11 @@ SELECT MIN(booking__paid_at__day) AS booking__paid_at__day__min , MAX(booking__paid_at__day) AS booking__paid_at__day__max FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['booking__paid_at__day',] SELECT DATE_TRUNC('day', paid_at) AS booking__paid_at__day FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('day', paid_at) -) subq_3 +) subq_1 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time_quarter__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time_quarter__plan0.sql index 1f038042ce..3ac6fbbcbf 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time_quarter__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time_quarter__plan0.sql @@ -1,104 +1,13 @@ -- Calculate min and max SELECT - MIN(subq_1.booking__paid_at__quarter) AS booking__paid_at__quarter__min - , MAX(subq_1.booking__paid_at__quarter) AS booking__paid_at__quarter__max + MIN(subq_0.booking__paid_at__quarter) AS booking__paid_at__quarter__min + , MAX(subq_0.booking__paid_at__quarter) AS booking__paid_at__quarter__max FROM ( + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['booking__paid_at__quarter',] SELECT - subq_0.booking__paid_at__quarter - 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 + DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) AS booking__paid_at__quarter + FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY - subq_0.booking__paid_at__quarter -) subq_1 + DATE_TRUNC('quarter', bookings_source_src_28000.paid_at) +) subq_0 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time_quarter__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time_quarter__plan0_optimized.sql index 5ff0fa4feb..4bb3495c42 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time_quarter__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_min_max_only_time_quarter__plan0_optimized.sql @@ -3,11 +3,11 @@ SELECT MIN(booking__paid_at__quarter) AS booking__paid_at__quarter__min , MAX(booking__paid_at__quarter) AS booking__paid_at__quarter__max FROM ( - -- Read Elements From Semantic Model 'bookings_source' + -- Read From SemanticModelDataSet('bookings_source') -- Pass Only Elements: ['booking__paid_at__quarter',] SELECT DATE_TRUNC('quarter', paid_at) AS booking__paid_at__quarter FROM ***************************.fct_bookings bookings_source_src_28000 GROUP BY DATE_TRUNC('quarter', paid_at) -) subq_3 +) subq_1 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0.sql index 2db2db0066..4c9ccd8cf6 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0.sql @@ -1,458 +1,256 @@ -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.listing__user__home_state_latest - , subq_10.bookings + subq_6.metric_time__day + , subq_6.listing__user__home_state_latest + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , subq_9.listing__user__home_state_latest - , SUM(subq_9.bookings) AS bookings + subq_5.metric_time__day + , subq_5.listing__user__home_state_latest + , SUM(subq_5.bookings) AS bookings FROM ( + -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__user__home_state_latest', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.listing__user__home_state_latest - , subq_8.bookings + subq_1.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] + SELECT + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.bookings + 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_26000.booking_value + , bookings_source_src_26000.guest_id AS bookers + , bookings_source_src_26000.booking_value AS average_booking_value + , bookings_source_src_26000.booking_value AS booking_payments + , bookings_source_src_26000.is_instant + , DATE_TRUNC('day', bookings_source_src_26000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_26000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_26000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_26000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS paid_at__extract_doy + , bookings_source_src_26000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_26000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_26000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_26000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_26000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_26000.listing_id AS listing + , bookings_source_src_26000.guest_id AS guest + , bookings_source_src_26000.host_id AS host + , bookings_source_src_26000.guest_id AS user + , bookings_source_src_26000.listing_id AS booking__listing + , bookings_source_src_26000.guest_id AS booking__guest + , bookings_source_src_26000.host_id AS booking__host + , bookings_source_src_26000.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_26000 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( -- Join Standard Outputs + -- Pass Only Elements: ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] SELECT - subq_2.metric_time__day AS metric_time__day - , subq_7.window_start__day AS listing__window_start__day - , subq_7.window_end__day AS listing__window_end__day + subq_2.window_start__day AS window_start__day + , subq_2.window_end__day AS window_end__day , subq_2.listing AS listing - , subq_7.user__home_state_latest AS listing__user__home_state_latest - , subq_2.bookings AS bookings FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] + -- Read Elements From Semantic Model 'listings' SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.user - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.booking__user - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.bookers - , subq_0.average_booking_value - 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_26000.booking_value - , bookings_source_src_26000.guest_id AS bookers - , bookings_source_src_26000.booking_value AS average_booking_value - , bookings_source_src_26000.booking_value AS booking_payments - , bookings_source_src_26000.is_instant - , DATE_TRUNC('day', bookings_source_src_26000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_26000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_26000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_26000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds) AS ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS paid_at__extract_doy - , bookings_source_src_26000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_26000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_26000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_26000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_26000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds) AS booking__ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_26000.listing_id AS listing - , bookings_source_src_26000.guest_id AS guest - , bookings_source_src_26000.host_id AS host - , bookings_source_src_26000.guest_id AS user - , bookings_source_src_26000.listing_id AS booking__listing - , bookings_source_src_26000.guest_id AS booking__guest - , bookings_source_src_26000.host_id AS booking__host - , bookings_source_src_26000.guest_id AS booking__user - FROM ***************************.fct_bookings bookings_source_src_26000 - ) subq_0 - ) subq_1 + listings_src_26000.active_from AS window_start__day + , DATE_TRUNC('week', listings_src_26000.active_from) AS window_start__week + , DATE_TRUNC('month', listings_src_26000.active_from) AS window_start__month + , DATE_TRUNC('quarter', listings_src_26000.active_from) AS window_start__quarter + , DATE_TRUNC('year', listings_src_26000.active_from) AS window_start__year + , EXTRACT(year FROM listings_src_26000.active_from) AS window_start__extract_year + , EXTRACT(quarter FROM listings_src_26000.active_from) AS window_start__extract_quarter + , EXTRACT(month FROM listings_src_26000.active_from) AS window_start__extract_month + , EXTRACT(day FROM listings_src_26000.active_from) AS window_start__extract_day + , EXTRACT(isodow FROM listings_src_26000.active_from) AS window_start__extract_dow + , EXTRACT(doy FROM listings_src_26000.active_from) AS window_start__extract_doy + , listings_src_26000.active_to AS window_end__day + , DATE_TRUNC('week', listings_src_26000.active_to) AS window_end__week + , DATE_TRUNC('month', listings_src_26000.active_to) AS window_end__month + , DATE_TRUNC('quarter', listings_src_26000.active_to) AS window_end__quarter + , DATE_TRUNC('year', listings_src_26000.active_to) AS window_end__year + , EXTRACT(year FROM listings_src_26000.active_to) AS window_end__extract_year + , EXTRACT(quarter FROM listings_src_26000.active_to) AS window_end__extract_quarter + , EXTRACT(month FROM listings_src_26000.active_to) AS window_end__extract_month + , EXTRACT(day FROM listings_src_26000.active_to) AS window_end__extract_day + , EXTRACT(isodow FROM listings_src_26000.active_to) AS window_end__extract_dow + , EXTRACT(doy FROM listings_src_26000.active_to) AS window_end__extract_doy + , listings_src_26000.country + , listings_src_26000.is_lux + , listings_src_26000.capacity + , listings_src_26000.active_from AS listing__window_start__day + , DATE_TRUNC('week', listings_src_26000.active_from) AS listing__window_start__week + , DATE_TRUNC('month', listings_src_26000.active_from) AS listing__window_start__month + , DATE_TRUNC('quarter', listings_src_26000.active_from) AS listing__window_start__quarter + , DATE_TRUNC('year', listings_src_26000.active_from) AS listing__window_start__year + , EXTRACT(year FROM listings_src_26000.active_from) AS listing__window_start__extract_year + , EXTRACT(quarter FROM listings_src_26000.active_from) AS listing__window_start__extract_quarter + , EXTRACT(month FROM listings_src_26000.active_from) AS listing__window_start__extract_month + , EXTRACT(day FROM listings_src_26000.active_from) AS listing__window_start__extract_day + , EXTRACT(isodow FROM listings_src_26000.active_from) AS listing__window_start__extract_dow + , EXTRACT(doy FROM listings_src_26000.active_from) AS listing__window_start__extract_doy + , listings_src_26000.active_to AS listing__window_end__day + , DATE_TRUNC('week', listings_src_26000.active_to) AS listing__window_end__week + , DATE_TRUNC('month', listings_src_26000.active_to) AS listing__window_end__month + , DATE_TRUNC('quarter', listings_src_26000.active_to) AS listing__window_end__quarter + , DATE_TRUNC('year', listings_src_26000.active_to) AS listing__window_end__year + , EXTRACT(year FROM listings_src_26000.active_to) AS listing__window_end__extract_year + , EXTRACT(quarter FROM listings_src_26000.active_to) AS listing__window_end__extract_quarter + , EXTRACT(month FROM listings_src_26000.active_to) AS listing__window_end__extract_month + , EXTRACT(day FROM listings_src_26000.active_to) AS listing__window_end__extract_day + , EXTRACT(isodow FROM listings_src_26000.active_to) AS listing__window_end__extract_dow + , EXTRACT(doy FROM listings_src_26000.active_to) AS listing__window_end__extract_doy + , listings_src_26000.country AS listing__country + , listings_src_26000.is_lux AS listing__is_lux + , listings_src_26000.capacity AS listing__capacity + , listings_src_26000.listing_id AS listing + , listings_src_26000.user_id AS user + , listings_src_26000.user_id AS listing__user + FROM ***************************.dim_listings listings_src_26000 ) subq_2 LEFT OUTER JOIN ( - -- Pass Only Elements: ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] + -- Read From SemanticModelDataSet('users_latest') + -- Pass Only Elements: [ + -- 'home_state_latest', + -- 'user__home_state_latest', + -- 'ds__day', + -- 'ds__week', + -- 'ds__month', + -- 'ds__quarter', + -- 'ds__year', + -- 'ds__extract_year', + -- 'ds__extract_quarter', + -- 'ds__extract_month', + -- 'ds__extract_day', + -- 'ds__extract_dow', + -- 'ds__extract_doy', + -- 'user__ds__day', + -- 'user__ds__week', + -- 'user__ds__month', + -- 'user__ds__quarter', + -- 'user__ds__year', + -- 'user__ds__extract_year', + -- 'user__ds__extract_quarter', + -- 'user__ds__extract_month', + -- 'user__ds__extract_day', + -- 'user__ds__extract_dow', + -- 'user__ds__extract_doy', + -- 'user', + -- ] SELECT - subq_6.window_start__day - , subq_6.window_end__day - , subq_6.listing - , subq_6.user__home_state_latest - FROM ( - -- Join Standard Outputs - SELECT - subq_3.window_start__day AS window_start__day - , subq_3.window_start__week AS window_start__week - , subq_3.window_start__month AS window_start__month - , subq_3.window_start__quarter AS window_start__quarter - , subq_3.window_start__year AS window_start__year - , subq_3.window_start__extract_year AS window_start__extract_year - , subq_3.window_start__extract_quarter AS window_start__extract_quarter - , subq_3.window_start__extract_month AS window_start__extract_month - , subq_3.window_start__extract_day AS window_start__extract_day - , subq_3.window_start__extract_dow AS window_start__extract_dow - , subq_3.window_start__extract_doy AS window_start__extract_doy - , subq_3.window_end__day AS window_end__day - , subq_3.window_end__week AS window_end__week - , subq_3.window_end__month AS window_end__month - , subq_3.window_end__quarter AS window_end__quarter - , subq_3.window_end__year AS window_end__year - , subq_3.window_end__extract_year AS window_end__extract_year - , subq_3.window_end__extract_quarter AS window_end__extract_quarter - , subq_3.window_end__extract_month AS window_end__extract_month - , subq_3.window_end__extract_day AS window_end__extract_day - , subq_3.window_end__extract_dow AS window_end__extract_dow - , subq_3.window_end__extract_doy AS window_end__extract_doy - , subq_3.listing__window_start__day AS listing__window_start__day - , subq_3.listing__window_start__week AS listing__window_start__week - , subq_3.listing__window_start__month AS listing__window_start__month - , subq_3.listing__window_start__quarter AS listing__window_start__quarter - , subq_3.listing__window_start__year AS listing__window_start__year - , subq_3.listing__window_start__extract_year AS listing__window_start__extract_year - , subq_3.listing__window_start__extract_quarter AS listing__window_start__extract_quarter - , subq_3.listing__window_start__extract_month AS listing__window_start__extract_month - , subq_3.listing__window_start__extract_day AS listing__window_start__extract_day - , subq_3.listing__window_start__extract_dow AS listing__window_start__extract_dow - , subq_3.listing__window_start__extract_doy AS listing__window_start__extract_doy - , subq_3.listing__window_end__day AS listing__window_end__day - , subq_3.listing__window_end__week AS listing__window_end__week - , subq_3.listing__window_end__month AS listing__window_end__month - , subq_3.listing__window_end__quarter AS listing__window_end__quarter - , subq_3.listing__window_end__year AS listing__window_end__year - , subq_3.listing__window_end__extract_year AS listing__window_end__extract_year - , subq_3.listing__window_end__extract_quarter AS listing__window_end__extract_quarter - , subq_3.listing__window_end__extract_month AS listing__window_end__extract_month - , subq_3.listing__window_end__extract_day AS listing__window_end__extract_day - , subq_3.listing__window_end__extract_dow AS listing__window_end__extract_dow - , subq_3.listing__window_end__extract_doy AS listing__window_end__extract_doy - , subq_5.ds__day AS user__ds__day - , subq_5.ds__week AS user__ds__week - , subq_5.ds__month AS user__ds__month - , subq_5.ds__quarter AS user__ds__quarter - , subq_5.ds__year AS user__ds__year - , subq_5.ds__extract_year AS user__ds__extract_year - , subq_5.ds__extract_quarter AS user__ds__extract_quarter - , subq_5.ds__extract_month AS user__ds__extract_month - , subq_5.ds__extract_day AS user__ds__extract_day - , subq_5.ds__extract_dow AS user__ds__extract_dow - , subq_5.ds__extract_doy AS user__ds__extract_doy - , subq_3.listing AS listing - , subq_3.user AS user - , subq_3.listing__user AS listing__user - , subq_3.country AS country - , subq_3.is_lux AS is_lux - , subq_3.capacity AS capacity - , subq_3.listing__country AS listing__country - , subq_3.listing__is_lux AS listing__is_lux - , subq_3.listing__capacity AS listing__capacity - , subq_5.home_state_latest AS user__home_state_latest - FROM ( - -- Read Elements From Semantic Model 'listings' - SELECT - listings_src_26000.active_from AS window_start__day - , DATE_TRUNC('week', listings_src_26000.active_from) AS window_start__week - , DATE_TRUNC('month', listings_src_26000.active_from) AS window_start__month - , DATE_TRUNC('quarter', listings_src_26000.active_from) AS window_start__quarter - , DATE_TRUNC('year', listings_src_26000.active_from) AS window_start__year - , EXTRACT(year FROM listings_src_26000.active_from) AS window_start__extract_year - , EXTRACT(quarter FROM listings_src_26000.active_from) AS window_start__extract_quarter - , EXTRACT(month FROM listings_src_26000.active_from) AS window_start__extract_month - , EXTRACT(day FROM listings_src_26000.active_from) AS window_start__extract_day - , EXTRACT(isodow FROM listings_src_26000.active_from) AS window_start__extract_dow - , EXTRACT(doy FROM listings_src_26000.active_from) AS window_start__extract_doy - , listings_src_26000.active_to AS window_end__day - , DATE_TRUNC('week', listings_src_26000.active_to) AS window_end__week - , DATE_TRUNC('month', listings_src_26000.active_to) AS window_end__month - , DATE_TRUNC('quarter', listings_src_26000.active_to) AS window_end__quarter - , DATE_TRUNC('year', listings_src_26000.active_to) AS window_end__year - , EXTRACT(year FROM listings_src_26000.active_to) AS window_end__extract_year - , EXTRACT(quarter FROM listings_src_26000.active_to) AS window_end__extract_quarter - , EXTRACT(month FROM listings_src_26000.active_to) AS window_end__extract_month - , EXTRACT(day FROM listings_src_26000.active_to) AS window_end__extract_day - , EXTRACT(isodow FROM listings_src_26000.active_to) AS window_end__extract_dow - , EXTRACT(doy FROM listings_src_26000.active_to) AS window_end__extract_doy - , listings_src_26000.country - , listings_src_26000.is_lux - , listings_src_26000.capacity - , listings_src_26000.active_from AS listing__window_start__day - , DATE_TRUNC('week', listings_src_26000.active_from) AS listing__window_start__week - , DATE_TRUNC('month', listings_src_26000.active_from) AS listing__window_start__month - , DATE_TRUNC('quarter', listings_src_26000.active_from) AS listing__window_start__quarter - , DATE_TRUNC('year', listings_src_26000.active_from) AS listing__window_start__year - , EXTRACT(year FROM listings_src_26000.active_from) AS listing__window_start__extract_year - , EXTRACT(quarter FROM listings_src_26000.active_from) AS listing__window_start__extract_quarter - , EXTRACT(month FROM listings_src_26000.active_from) AS listing__window_start__extract_month - , EXTRACT(day FROM listings_src_26000.active_from) AS listing__window_start__extract_day - , EXTRACT(isodow FROM listings_src_26000.active_from) AS listing__window_start__extract_dow - , EXTRACT(doy FROM listings_src_26000.active_from) AS listing__window_start__extract_doy - , listings_src_26000.active_to AS listing__window_end__day - , DATE_TRUNC('week', listings_src_26000.active_to) AS listing__window_end__week - , DATE_TRUNC('month', listings_src_26000.active_to) AS listing__window_end__month - , DATE_TRUNC('quarter', listings_src_26000.active_to) AS listing__window_end__quarter - , DATE_TRUNC('year', listings_src_26000.active_to) AS listing__window_end__year - , EXTRACT(year FROM listings_src_26000.active_to) AS listing__window_end__extract_year - , EXTRACT(quarter FROM listings_src_26000.active_to) AS listing__window_end__extract_quarter - , EXTRACT(month FROM listings_src_26000.active_to) AS listing__window_end__extract_month - , EXTRACT(day FROM listings_src_26000.active_to) AS listing__window_end__extract_day - , EXTRACT(isodow FROM listings_src_26000.active_to) AS listing__window_end__extract_dow - , EXTRACT(doy FROM listings_src_26000.active_to) AS listing__window_end__extract_doy - , listings_src_26000.country AS listing__country - , listings_src_26000.is_lux AS listing__is_lux - , listings_src_26000.capacity AS listing__capacity - , listings_src_26000.listing_id AS listing - , listings_src_26000.user_id AS user - , listings_src_26000.user_id AS listing__user - FROM ***************************.dim_listings listings_src_26000 - ) subq_3 - LEFT OUTER JOIN ( - -- Pass Only Elements: [ - -- 'home_state_latest', - -- 'user__home_state_latest', - -- 'ds__day', - -- 'ds__week', - -- 'ds__month', - -- 'ds__quarter', - -- 'ds__year', - -- 'ds__extract_year', - -- 'ds__extract_quarter', - -- 'ds__extract_month', - -- 'ds__extract_day', - -- 'ds__extract_dow', - -- 'ds__extract_doy', - -- 'user__ds__day', - -- 'user__ds__week', - -- 'user__ds__month', - -- 'user__ds__quarter', - -- 'user__ds__year', - -- 'user__ds__extract_year', - -- 'user__ds__extract_quarter', - -- 'user__ds__extract_month', - -- 'user__ds__extract_day', - -- 'user__ds__extract_dow', - -- 'user__ds__extract_doy', - -- 'user', - -- ] - SELECT - 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.user__ds__day - , subq_4.user__ds__week - , subq_4.user__ds__month - , subq_4.user__ds__quarter - , subq_4.user__ds__year - , subq_4.user__ds__extract_year - , subq_4.user__ds__extract_quarter - , subq_4.user__ds__extract_month - , subq_4.user__ds__extract_day - , subq_4.user__ds__extract_dow - , subq_4.user__ds__extract_doy - , subq_4.user - , subq_4.home_state_latest - , subq_4.user__home_state_latest - FROM ( - -- Read Elements From Semantic Model 'users_latest' - SELECT - DATE_TRUNC('day', users_latest_src_26000.ds) AS ds__day - , DATE_TRUNC('week', users_latest_src_26000.ds) AS ds__week - , DATE_TRUNC('month', users_latest_src_26000.ds) AS ds__month - , DATE_TRUNC('quarter', users_latest_src_26000.ds) AS ds__quarter - , DATE_TRUNC('year', users_latest_src_26000.ds) AS ds__year - , EXTRACT(year FROM users_latest_src_26000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_latest_src_26000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_latest_src_26000.ds) AS ds__extract_month - , EXTRACT(day FROM users_latest_src_26000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_latest_src_26000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_latest_src_26000.ds) AS ds__extract_doy - , users_latest_src_26000.home_state_latest - , DATE_TRUNC('day', users_latest_src_26000.ds) AS user__ds__day - , DATE_TRUNC('week', users_latest_src_26000.ds) AS user__ds__week - , DATE_TRUNC('month', users_latest_src_26000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_latest_src_26000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_latest_src_26000.ds) AS user__ds__year - , EXTRACT(year FROM users_latest_src_26000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_latest_src_26000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_latest_src_26000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_latest_src_26000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_latest_src_26000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_latest_src_26000.ds) AS user__ds__extract_doy - , users_latest_src_26000.home_state_latest AS user__home_state_latest - , users_latest_src_26000.user_id AS user - FROM ***************************.dim_users_latest users_latest_src_26000 - ) subq_4 - ) subq_5 - ON - subq_3.user = subq_5.user - ) subq_6 - ) subq_7 + DATE_TRUNC('day', users_latest_src_26000.ds) AS ds__day + , DATE_TRUNC('week', users_latest_src_26000.ds) AS ds__week + , DATE_TRUNC('month', users_latest_src_26000.ds) AS ds__month + , DATE_TRUNC('quarter', users_latest_src_26000.ds) AS ds__quarter + , DATE_TRUNC('year', users_latest_src_26000.ds) AS ds__year + , EXTRACT(year FROM users_latest_src_26000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_latest_src_26000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_latest_src_26000.ds) AS ds__extract_month + , EXTRACT(day FROM users_latest_src_26000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_latest_src_26000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_latest_src_26000.ds) AS ds__extract_doy + , users_latest_src_26000.home_state_latest + , DATE_TRUNC('day', users_latest_src_26000.ds) AS user__ds__day + , DATE_TRUNC('week', users_latest_src_26000.ds) AS user__ds__week + , DATE_TRUNC('month', users_latest_src_26000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_latest_src_26000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_latest_src_26000.ds) AS user__ds__year + , EXTRACT(year FROM users_latest_src_26000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_latest_src_26000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_latest_src_26000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_latest_src_26000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_latest_src_26000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_latest_src_26000.ds) AS user__ds__extract_doy + , users_latest_src_26000.home_state_latest AS user__home_state_latest + , users_latest_src_26000.user_id AS user + FROM ***************************.dim_users_latest users_latest_src_26000 + ) subq_3 ON + subq_2.user = subq_3.user + ) subq_4 + ON + ( + subq_1.listing = subq_4.listing + ) AND ( ( - subq_2.listing = subq_7.listing + subq_1.metric_time__day >= subq_4.window_start__day ) AND ( ( - subq_2.metric_time__day >= subq_7.window_start__day - ) AND ( - ( - subq_2.metric_time__day < subq_7.window_end__day - ) OR ( - subq_7.window_end__day IS NULL - ) + subq_1.metric_time__day < subq_4.window_end__day + ) OR ( + subq_4.window_end__day IS NULL ) ) - ) subq_8 - ) subq_9 + ) + ) subq_5 GROUP BY - subq_9.metric_time__day - , subq_9.listing__user__home_state_latest -) subq_10 + subq_5.metric_time__day + , subq_5.listing__user__home_state_latest +) subq_6 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0_optimized.sql index 43c459ada2..bd1e318b6e 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_through_scd_dimension__plan0_optimized.sql @@ -3,9 +3,9 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day AS metric_time__day - , subq_18.user__home_state_latest AS listing__user__home_state_latest - , SUM(subq_13.bookings) AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_12.listing__user__home_state_latest AS listing__user__home_state_latest + , SUM(subq_8.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -15,7 +15,7 @@ FROM ( , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_26000 -) subq_13 +) subq_8 LEFT OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['user__home_state_latest', 'window_start__day', 'window_end__day', 'listing'] @@ -23,27 +23,26 @@ LEFT OUTER JOIN ( listings_src_26000.active_from AS window_start__day , listings_src_26000.active_to AS window_end__day , listings_src_26000.listing_id AS listing - , users_latest_src_26000.home_state_latest AS user__home_state_latest FROM ***************************.dim_listings listings_src_26000 LEFT OUTER JOIN ***************************.dim_users_latest users_latest_src_26000 ON listings_src_26000.user_id = users_latest_src_26000.user_id -) subq_18 +) subq_11 ON ( - subq_13.listing = subq_18.listing + subq_8.listing = subq_11.listing ) AND ( ( - subq_13.metric_time__day >= subq_18.window_start__day + subq_8.metric_time__day >= subq_11.window_start__day ) AND ( ( - subq_13.metric_time__day < subq_18.window_end__day + subq_8.metric_time__day < subq_11.window_end__day ) OR ( - subq_18.window_end__day IS NULL + subq_11.window_end__day IS NULL ) ) ) GROUP BY - subq_13.metric_time__day - , subq_18.user__home_state_latest + subq_8.metric_time__day + , subq_12.listing__user__home_state_latest diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_to_scd_dimension__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_to_scd_dimension__plan0.sql index b2dfef8dbc..21bad859ef 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_to_scd_dimension__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_to_scd_dimension__plan0.sql @@ -1,435 +1,248 @@ -- Compute Metrics via Expressions SELECT - subq_10.metric_time__day - , subq_10.listing__lux_listing__is_confirmed_lux - , subq_10.bookings + subq_6.metric_time__day + , subq_6.listing__lux_listing__is_confirmed_lux + , subq_6.bookings FROM ( -- Aggregate Measures SELECT - subq_9.metric_time__day - , subq_9.listing__lux_listing__is_confirmed_lux - , SUM(subq_9.bookings) AS bookings + subq_5.metric_time__day + , subq_5.listing__lux_listing__is_confirmed_lux + , SUM(subq_5.bookings) AS bookings FROM ( + -- Join Standard Outputs -- Pass Only Elements: ['bookings', 'listing__lux_listing__is_confirmed_lux', 'metric_time__day'] SELECT - subq_8.metric_time__day - , subq_8.listing__lux_listing__is_confirmed_lux - , subq_8.bookings + subq_1.metric_time__day AS metric_time__day + , subq_1.bookings AS bookings FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] + SELECT + subq_0.ds__day AS metric_time__day + , subq_0.listing + , subq_0.bookings + 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_26000.booking_value + , bookings_source_src_26000.guest_id AS bookers + , bookings_source_src_26000.booking_value AS average_booking_value + , bookings_source_src_26000.booking_value AS booking_payments + , bookings_source_src_26000.is_instant + , DATE_TRUNC('day', bookings_source_src_26000.ds) AS ds__day + , DATE_TRUNC('week', bookings_source_src_26000.ds) AS ds__week + , DATE_TRUNC('month', bookings_source_src_26000.ds) AS ds__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS ds__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds) AS ds__year + , EXTRACT(year FROM bookings_source_src_26000.ds) AS ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds) AS ds__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds) AS ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds) AS ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS paid_at__day + , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS paid_at__week + , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS paid_at__year + , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS paid_at__extract_doy + , bookings_source_src_26000.is_instant AS booking__is_instant + , DATE_TRUNC('day', bookings_source_src_26000.ds) AS booking__ds__day + , DATE_TRUNC('week', bookings_source_src_26000.ds) AS booking__ds__week + , DATE_TRUNC('month', bookings_source_src_26000.ds) AS booking__ds__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS booking__ds__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds) AS booking__ds__year + , EXTRACT(year FROM bookings_source_src_26000.ds) AS booking__ds__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS booking__ds__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds) AS booking__ds__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds) AS booking__ds__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS booking__ds__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds) AS booking__ds__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__day + , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__week + , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__month + , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__quarter + , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__year + , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_month + , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_doy + , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS booking__paid_at__day + , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS booking__paid_at__week + , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS booking__paid_at__month + , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS booking__paid_at__quarter + , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS booking__paid_at__year + , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_year + , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_quarter + , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_month + , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_day + , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_dow + , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_doy + , bookings_source_src_26000.listing_id AS listing + , bookings_source_src_26000.guest_id AS guest + , bookings_source_src_26000.host_id AS host + , bookings_source_src_26000.guest_id AS user + , bookings_source_src_26000.listing_id AS booking__listing + , bookings_source_src_26000.guest_id AS booking__guest + , bookings_source_src_26000.host_id AS booking__host + , bookings_source_src_26000.guest_id AS booking__user + FROM ***************************.fct_bookings bookings_source_src_26000 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( -- Join Standard Outputs + -- Pass Only Elements: ['lux_listing__is_confirmed_lux', 'lux_listing__window_start__day', 'lux_listing__window_end__day', 'listing'] SELECT - subq_2.metric_time__day AS metric_time__day - , subq_7.lux_listing__window_start__day AS listing__lux_listing__window_start__day - , subq_7.lux_listing__window_end__day AS listing__lux_listing__window_end__day - , subq_2.listing AS listing - , subq_7.lux_listing__is_confirmed_lux AS listing__lux_listing__is_confirmed_lux - , subq_2.bookings AS bookings + subq_2.listing AS listing FROM ( - -- Pass Only Elements: ['bookings', 'metric_time__day', 'listing'] + -- Read Elements From Semantic Model 'lux_listing_mapping' SELECT - subq_1.metric_time__day - , subq_1.listing - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.user - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.booking__user - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.bookers - , subq_0.average_booking_value - 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_26000.booking_value - , bookings_source_src_26000.guest_id AS bookers - , bookings_source_src_26000.booking_value AS average_booking_value - , bookings_source_src_26000.booking_value AS booking_payments - , bookings_source_src_26000.is_instant - , DATE_TRUNC('day', bookings_source_src_26000.ds) AS ds__day - , DATE_TRUNC('week', bookings_source_src_26000.ds) AS ds__week - , DATE_TRUNC('month', bookings_source_src_26000.ds) AS ds__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS ds__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds) AS ds__year - , EXTRACT(year FROM bookings_source_src_26000.ds) AS ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds) AS ds__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds) AS ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds) AS ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS paid_at__day - , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS paid_at__week - , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS paid_at__year - , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS paid_at__extract_doy - , bookings_source_src_26000.is_instant AS booking__is_instant - , DATE_TRUNC('day', bookings_source_src_26000.ds) AS booking__ds__day - , DATE_TRUNC('week', bookings_source_src_26000.ds) AS booking__ds__week - , DATE_TRUNC('month', bookings_source_src_26000.ds) AS booking__ds__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds) AS booking__ds__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds) AS booking__ds__year - , EXTRACT(year FROM bookings_source_src_26000.ds) AS booking__ds__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds) AS booking__ds__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds) AS booking__ds__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds) AS booking__ds__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds) AS booking__ds__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds) AS booking__ds__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__day - , DATE_TRUNC('week', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__week - , DATE_TRUNC('month', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__month - , DATE_TRUNC('quarter', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__quarter - , DATE_TRUNC('year', bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__year - , EXTRACT(year FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_month - , EXTRACT(day FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.ds_partitioned) AS booking__ds_partitioned__extract_doy - , DATE_TRUNC('day', bookings_source_src_26000.paid_at) AS booking__paid_at__day - , DATE_TRUNC('week', bookings_source_src_26000.paid_at) AS booking__paid_at__week - , DATE_TRUNC('month', bookings_source_src_26000.paid_at) AS booking__paid_at__month - , DATE_TRUNC('quarter', bookings_source_src_26000.paid_at) AS booking__paid_at__quarter - , DATE_TRUNC('year', bookings_source_src_26000.paid_at) AS booking__paid_at__year - , EXTRACT(year FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_year - , EXTRACT(quarter FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_quarter - , EXTRACT(month FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_month - , EXTRACT(day FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_day - , EXTRACT(isodow FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_dow - , EXTRACT(doy FROM bookings_source_src_26000.paid_at) AS booking__paid_at__extract_doy - , bookings_source_src_26000.listing_id AS listing - , bookings_source_src_26000.guest_id AS guest - , bookings_source_src_26000.host_id AS host - , bookings_source_src_26000.guest_id AS user - , bookings_source_src_26000.listing_id AS booking__listing - , bookings_source_src_26000.guest_id AS booking__guest - , bookings_source_src_26000.host_id AS booking__host - , bookings_source_src_26000.guest_id AS booking__user - FROM ***************************.fct_bookings bookings_source_src_26000 - ) subq_0 - ) subq_1 + lux_listing_mapping_src_26000.listing_id AS listing + , lux_listing_mapping_src_26000.lux_listing_id AS lux_listing + , lux_listing_mapping_src_26000.lux_listing_id AS listing__lux_listing + FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_26000 ) subq_2 LEFT OUTER JOIN ( - -- Pass Only Elements: ['lux_listing__is_confirmed_lux', 'lux_listing__window_start__day', 'lux_listing__window_end__day', 'listing'] + -- Read From SemanticModelDataSet('lux_listings') + -- Pass Only Elements: [ + -- 'is_confirmed_lux', + -- 'lux_listing__is_confirmed_lux', + -- 'window_start__day', + -- 'window_start__week', + -- 'window_start__month', + -- 'window_start__quarter', + -- 'window_start__year', + -- 'window_start__extract_year', + -- 'window_start__extract_quarter', + -- 'window_start__extract_month', + -- 'window_start__extract_day', + -- 'window_start__extract_dow', + -- 'window_start__extract_doy', + -- 'window_end__day', + -- 'window_end__week', + -- 'window_end__month', + -- 'window_end__quarter', + -- 'window_end__year', + -- 'window_end__extract_year', + -- 'window_end__extract_quarter', + -- 'window_end__extract_month', + -- 'window_end__extract_day', + -- 'window_end__extract_dow', + -- 'window_end__extract_doy', + -- 'lux_listing__window_start__day', + -- 'lux_listing__window_start__week', + -- 'lux_listing__window_start__month', + -- 'lux_listing__window_start__quarter', + -- 'lux_listing__window_start__year', + -- 'lux_listing__window_start__extract_year', + -- 'lux_listing__window_start__extract_quarter', + -- 'lux_listing__window_start__extract_month', + -- 'lux_listing__window_start__extract_day', + -- 'lux_listing__window_start__extract_dow', + -- 'lux_listing__window_start__extract_doy', + -- 'lux_listing__window_end__day', + -- 'lux_listing__window_end__week', + -- 'lux_listing__window_end__month', + -- 'lux_listing__window_end__quarter', + -- 'lux_listing__window_end__year', + -- 'lux_listing__window_end__extract_year', + -- 'lux_listing__window_end__extract_quarter', + -- 'lux_listing__window_end__extract_month', + -- 'lux_listing__window_end__extract_day', + -- 'lux_listing__window_end__extract_dow', + -- 'lux_listing__window_end__extract_doy', + -- 'lux_listing', + -- ] SELECT - subq_6.lux_listing__window_start__day - , subq_6.lux_listing__window_end__day - , subq_6.listing - , subq_6.lux_listing__is_confirmed_lux - FROM ( - -- Join Standard Outputs - SELECT - subq_5.window_start__day AS lux_listing__window_start__day - , subq_5.window_start__week AS lux_listing__window_start__week - , subq_5.window_start__month AS lux_listing__window_start__month - , subq_5.window_start__quarter AS lux_listing__window_start__quarter - , subq_5.window_start__year AS lux_listing__window_start__year - , subq_5.window_start__extract_year AS lux_listing__window_start__extract_year - , subq_5.window_start__extract_quarter AS lux_listing__window_start__extract_quarter - , subq_5.window_start__extract_month AS lux_listing__window_start__extract_month - , subq_5.window_start__extract_day AS lux_listing__window_start__extract_day - , subq_5.window_start__extract_dow AS lux_listing__window_start__extract_dow - , subq_5.window_start__extract_doy AS lux_listing__window_start__extract_doy - , subq_5.window_end__day AS lux_listing__window_end__day - , subq_5.window_end__week AS lux_listing__window_end__week - , subq_5.window_end__month AS lux_listing__window_end__month - , subq_5.window_end__quarter AS lux_listing__window_end__quarter - , subq_5.window_end__year AS lux_listing__window_end__year - , subq_5.window_end__extract_year AS lux_listing__window_end__extract_year - , subq_5.window_end__extract_quarter AS lux_listing__window_end__extract_quarter - , subq_5.window_end__extract_month AS lux_listing__window_end__extract_month - , subq_5.window_end__extract_day AS lux_listing__window_end__extract_day - , subq_5.window_end__extract_dow AS lux_listing__window_end__extract_dow - , subq_5.window_end__extract_doy AS lux_listing__window_end__extract_doy - , subq_3.listing AS listing - , subq_3.lux_listing AS lux_listing - , subq_3.listing__lux_listing AS listing__lux_listing - , subq_5.is_confirmed_lux AS lux_listing__is_confirmed_lux - FROM ( - -- Read Elements From Semantic Model 'lux_listing_mapping' - SELECT - lux_listing_mapping_src_26000.listing_id AS listing - , lux_listing_mapping_src_26000.lux_listing_id AS lux_listing - , lux_listing_mapping_src_26000.lux_listing_id AS listing__lux_listing - FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_26000 - ) subq_3 - LEFT OUTER JOIN ( - -- Pass Only Elements: [ - -- 'is_confirmed_lux', - -- 'lux_listing__is_confirmed_lux', - -- 'window_start__day', - -- 'window_start__week', - -- 'window_start__month', - -- 'window_start__quarter', - -- 'window_start__year', - -- 'window_start__extract_year', - -- 'window_start__extract_quarter', - -- 'window_start__extract_month', - -- 'window_start__extract_day', - -- 'window_start__extract_dow', - -- 'window_start__extract_doy', - -- 'window_end__day', - -- 'window_end__week', - -- 'window_end__month', - -- 'window_end__quarter', - -- 'window_end__year', - -- 'window_end__extract_year', - -- 'window_end__extract_quarter', - -- 'window_end__extract_month', - -- 'window_end__extract_day', - -- 'window_end__extract_dow', - -- 'window_end__extract_doy', - -- 'lux_listing__window_start__day', - -- 'lux_listing__window_start__week', - -- 'lux_listing__window_start__month', - -- 'lux_listing__window_start__quarter', - -- 'lux_listing__window_start__year', - -- 'lux_listing__window_start__extract_year', - -- 'lux_listing__window_start__extract_quarter', - -- 'lux_listing__window_start__extract_month', - -- 'lux_listing__window_start__extract_day', - -- 'lux_listing__window_start__extract_dow', - -- 'lux_listing__window_start__extract_doy', - -- 'lux_listing__window_end__day', - -- 'lux_listing__window_end__week', - -- 'lux_listing__window_end__month', - -- 'lux_listing__window_end__quarter', - -- 'lux_listing__window_end__year', - -- 'lux_listing__window_end__extract_year', - -- 'lux_listing__window_end__extract_quarter', - -- 'lux_listing__window_end__extract_month', - -- 'lux_listing__window_end__extract_day', - -- 'lux_listing__window_end__extract_dow', - -- 'lux_listing__window_end__extract_doy', - -- 'lux_listing', - -- ] - SELECT - subq_4.window_start__day - , subq_4.window_start__week - , subq_4.window_start__month - , subq_4.window_start__quarter - , subq_4.window_start__year - , subq_4.window_start__extract_year - , subq_4.window_start__extract_quarter - , subq_4.window_start__extract_month - , subq_4.window_start__extract_day - , subq_4.window_start__extract_dow - , subq_4.window_start__extract_doy - , subq_4.window_end__day - , subq_4.window_end__week - , subq_4.window_end__month - , subq_4.window_end__quarter - , subq_4.window_end__year - , subq_4.window_end__extract_year - , subq_4.window_end__extract_quarter - , subq_4.window_end__extract_month - , subq_4.window_end__extract_day - , subq_4.window_end__extract_dow - , subq_4.window_end__extract_doy - , subq_4.lux_listing__window_start__day - , subq_4.lux_listing__window_start__week - , subq_4.lux_listing__window_start__month - , subq_4.lux_listing__window_start__quarter - , subq_4.lux_listing__window_start__year - , subq_4.lux_listing__window_start__extract_year - , subq_4.lux_listing__window_start__extract_quarter - , subq_4.lux_listing__window_start__extract_month - , subq_4.lux_listing__window_start__extract_day - , subq_4.lux_listing__window_start__extract_dow - , subq_4.lux_listing__window_start__extract_doy - , subq_4.lux_listing__window_end__day - , subq_4.lux_listing__window_end__week - , subq_4.lux_listing__window_end__month - , subq_4.lux_listing__window_end__quarter - , subq_4.lux_listing__window_end__year - , subq_4.lux_listing__window_end__extract_year - , subq_4.lux_listing__window_end__extract_quarter - , subq_4.lux_listing__window_end__extract_month - , subq_4.lux_listing__window_end__extract_day - , subq_4.lux_listing__window_end__extract_dow - , subq_4.lux_listing__window_end__extract_doy - , subq_4.lux_listing - , subq_4.is_confirmed_lux - , subq_4.lux_listing__is_confirmed_lux - FROM ( - -- Read Elements From Semantic Model 'lux_listings' - SELECT - lux_listings_src_26000.valid_from AS window_start__day - , DATE_TRUNC('week', lux_listings_src_26000.valid_from) AS window_start__week - , DATE_TRUNC('month', lux_listings_src_26000.valid_from) AS window_start__month - , DATE_TRUNC('quarter', lux_listings_src_26000.valid_from) AS window_start__quarter - , DATE_TRUNC('year', lux_listings_src_26000.valid_from) AS window_start__year - , EXTRACT(year FROM lux_listings_src_26000.valid_from) AS window_start__extract_year - , EXTRACT(quarter FROM lux_listings_src_26000.valid_from) AS window_start__extract_quarter - , EXTRACT(month FROM lux_listings_src_26000.valid_from) AS window_start__extract_month - , EXTRACT(day FROM lux_listings_src_26000.valid_from) AS window_start__extract_day - , EXTRACT(isodow FROM lux_listings_src_26000.valid_from) AS window_start__extract_dow - , EXTRACT(doy FROM lux_listings_src_26000.valid_from) AS window_start__extract_doy - , lux_listings_src_26000.valid_to AS window_end__day - , DATE_TRUNC('week', lux_listings_src_26000.valid_to) AS window_end__week - , DATE_TRUNC('month', lux_listings_src_26000.valid_to) AS window_end__month - , DATE_TRUNC('quarter', lux_listings_src_26000.valid_to) AS window_end__quarter - , DATE_TRUNC('year', lux_listings_src_26000.valid_to) AS window_end__year - , EXTRACT(year FROM lux_listings_src_26000.valid_to) AS window_end__extract_year - , EXTRACT(quarter FROM lux_listings_src_26000.valid_to) AS window_end__extract_quarter - , EXTRACT(month FROM lux_listings_src_26000.valid_to) AS window_end__extract_month - , EXTRACT(day FROM lux_listings_src_26000.valid_to) AS window_end__extract_day - , EXTRACT(isodow FROM lux_listings_src_26000.valid_to) AS window_end__extract_dow - , EXTRACT(doy FROM lux_listings_src_26000.valid_to) AS window_end__extract_doy - , lux_listings_src_26000.is_confirmed_lux - , lux_listings_src_26000.valid_from AS lux_listing__window_start__day - , DATE_TRUNC('week', lux_listings_src_26000.valid_from) AS lux_listing__window_start__week - , DATE_TRUNC('month', lux_listings_src_26000.valid_from) AS lux_listing__window_start__month - , DATE_TRUNC('quarter', lux_listings_src_26000.valid_from) AS lux_listing__window_start__quarter - , DATE_TRUNC('year', lux_listings_src_26000.valid_from) AS lux_listing__window_start__year - , EXTRACT(year FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_year - , EXTRACT(quarter FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_quarter - , EXTRACT(month FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_month - , EXTRACT(day FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_day - , EXTRACT(isodow FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_dow - , EXTRACT(doy FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_doy - , lux_listings_src_26000.valid_to AS lux_listing__window_end__day - , DATE_TRUNC('week', lux_listings_src_26000.valid_to) AS lux_listing__window_end__week - , DATE_TRUNC('month', lux_listings_src_26000.valid_to) AS lux_listing__window_end__month - , DATE_TRUNC('quarter', lux_listings_src_26000.valid_to) AS lux_listing__window_end__quarter - , DATE_TRUNC('year', lux_listings_src_26000.valid_to) AS lux_listing__window_end__year - , EXTRACT(year FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_year - , EXTRACT(quarter FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_quarter - , EXTRACT(month FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_month - , EXTRACT(day FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_day - , EXTRACT(isodow FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_dow - , EXTRACT(doy FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_doy - , lux_listings_src_26000.is_confirmed_lux AS lux_listing__is_confirmed_lux - , lux_listings_src_26000.lux_listing_id AS lux_listing - FROM ***************************.dim_lux_listings lux_listings_src_26000 - ) subq_4 - ) subq_5 - ON - subq_3.lux_listing = subq_5.lux_listing - ) subq_6 - ) subq_7 + lux_listings_src_26000.valid_from AS window_start__day + , DATE_TRUNC('week', lux_listings_src_26000.valid_from) AS window_start__week + , DATE_TRUNC('month', lux_listings_src_26000.valid_from) AS window_start__month + , DATE_TRUNC('quarter', lux_listings_src_26000.valid_from) AS window_start__quarter + , DATE_TRUNC('year', lux_listings_src_26000.valid_from) AS window_start__year + , EXTRACT(year FROM lux_listings_src_26000.valid_from) AS window_start__extract_year + , EXTRACT(quarter FROM lux_listings_src_26000.valid_from) AS window_start__extract_quarter + , EXTRACT(month FROM lux_listings_src_26000.valid_from) AS window_start__extract_month + , EXTRACT(day FROM lux_listings_src_26000.valid_from) AS window_start__extract_day + , EXTRACT(isodow FROM lux_listings_src_26000.valid_from) AS window_start__extract_dow + , EXTRACT(doy FROM lux_listings_src_26000.valid_from) AS window_start__extract_doy + , lux_listings_src_26000.valid_to AS window_end__day + , DATE_TRUNC('week', lux_listings_src_26000.valid_to) AS window_end__week + , DATE_TRUNC('month', lux_listings_src_26000.valid_to) AS window_end__month + , DATE_TRUNC('quarter', lux_listings_src_26000.valid_to) AS window_end__quarter + , DATE_TRUNC('year', lux_listings_src_26000.valid_to) AS window_end__year + , EXTRACT(year FROM lux_listings_src_26000.valid_to) AS window_end__extract_year + , EXTRACT(quarter FROM lux_listings_src_26000.valid_to) AS window_end__extract_quarter + , EXTRACT(month FROM lux_listings_src_26000.valid_to) AS window_end__extract_month + , EXTRACT(day FROM lux_listings_src_26000.valid_to) AS window_end__extract_day + , EXTRACT(isodow FROM lux_listings_src_26000.valid_to) AS window_end__extract_dow + , EXTRACT(doy FROM lux_listings_src_26000.valid_to) AS window_end__extract_doy + , lux_listings_src_26000.is_confirmed_lux + , lux_listings_src_26000.valid_from AS lux_listing__window_start__day + , DATE_TRUNC('week', lux_listings_src_26000.valid_from) AS lux_listing__window_start__week + , DATE_TRUNC('month', lux_listings_src_26000.valid_from) AS lux_listing__window_start__month + , DATE_TRUNC('quarter', lux_listings_src_26000.valid_from) AS lux_listing__window_start__quarter + , DATE_TRUNC('year', lux_listings_src_26000.valid_from) AS lux_listing__window_start__year + , EXTRACT(year FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_year + , EXTRACT(quarter FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_quarter + , EXTRACT(month FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_month + , EXTRACT(day FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_day + , EXTRACT(isodow FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_dow + , EXTRACT(doy FROM lux_listings_src_26000.valid_from) AS lux_listing__window_start__extract_doy + , lux_listings_src_26000.valid_to AS lux_listing__window_end__day + , DATE_TRUNC('week', lux_listings_src_26000.valid_to) AS lux_listing__window_end__week + , DATE_TRUNC('month', lux_listings_src_26000.valid_to) AS lux_listing__window_end__month + , DATE_TRUNC('quarter', lux_listings_src_26000.valid_to) AS lux_listing__window_end__quarter + , DATE_TRUNC('year', lux_listings_src_26000.valid_to) AS lux_listing__window_end__year + , EXTRACT(year FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_year + , EXTRACT(quarter FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_quarter + , EXTRACT(month FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_month + , EXTRACT(day FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_day + , EXTRACT(isodow FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_dow + , EXTRACT(doy FROM lux_listings_src_26000.valid_to) AS lux_listing__window_end__extract_doy + , lux_listings_src_26000.is_confirmed_lux AS lux_listing__is_confirmed_lux + , lux_listings_src_26000.lux_listing_id AS lux_listing + FROM ***************************.dim_lux_listings lux_listings_src_26000 + ) subq_3 ON + subq_2.lux_listing = subq_3.lux_listing + ) subq_4 + ON + ( + subq_1.listing = subq_4.listing + ) AND ( ( - subq_2.listing = subq_7.listing + subq_1.metric_time__day >= subq_4.window_start__day ) AND ( ( - subq_2.metric_time__day >= subq_7.lux_listing__window_start__day - ) AND ( - ( - subq_2.metric_time__day < subq_7.lux_listing__window_end__day - ) OR ( - subq_7.lux_listing__window_end__day IS NULL - ) + subq_1.metric_time__day < subq_4.window_end__day + ) OR ( + subq_4.window_end__day IS NULL ) ) - ) subq_8 - ) subq_9 + ) + ) subq_5 GROUP BY - subq_9.metric_time__day - , subq_9.listing__lux_listing__is_confirmed_lux -) subq_10 + subq_5.metric_time__day + , subq_5.listing__lux_listing__is_confirmed_lux +) subq_6 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_to_scd_dimension__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_to_scd_dimension__plan0_optimized.sql index d0d6125e14..432fca1b63 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_to_scd_dimension__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multi_hop_to_scd_dimension__plan0_optimized.sql @@ -3,9 +3,9 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_13.metric_time__day AS metric_time__day - , subq_18.lux_listing__is_confirmed_lux AS listing__lux_listing__is_confirmed_lux - , SUM(subq_13.bookings) AS bookings + subq_8.metric_time__day AS metric_time__day + , subq_12.listing__lux_listing__is_confirmed_lux AS listing__lux_listing__is_confirmed_lux + , SUM(subq_8.bookings) AS bookings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -15,35 +15,32 @@ FROM ( , listing_id AS listing , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_26000 -) subq_13 +) subq_8 LEFT OUTER JOIN ( -- Join Standard Outputs -- Pass Only Elements: ['lux_listing__is_confirmed_lux', 'lux_listing__window_start__day', 'lux_listing__window_end__day', 'listing'] SELECT - lux_listings_src_26000.valid_from AS lux_listing__window_start__day - , lux_listings_src_26000.valid_to AS lux_listing__window_end__day - , lux_listing_mapping_src_26000.listing_id AS listing - , lux_listings_src_26000.is_confirmed_lux AS lux_listing__is_confirmed_lux + lux_listing_mapping_src_26000.listing_id AS listing FROM ***************************.dim_lux_listing_id_mapping lux_listing_mapping_src_26000 LEFT OUTER JOIN ***************************.dim_lux_listings lux_listings_src_26000 ON lux_listing_mapping_src_26000.lux_listing_id = lux_listings_src_26000.lux_listing_id -) subq_18 +) subq_11 ON ( - subq_13.listing = subq_18.listing + subq_8.listing = subq_11.listing ) AND ( ( - subq_13.metric_time__day >= subq_18.lux_listing__window_start__day + subq_8.metric_time__day >= subq_11.window_start__day ) AND ( ( - subq_13.metric_time__day < subq_18.lux_listing__window_end__day + subq_8.metric_time__day < subq_11.window_end__day ) OR ( - subq_18.lux_listing__window_end__day IS NULL + subq_11.window_end__day IS NULL ) ) ) GROUP BY - subq_13.metric_time__day - , subq_18.lux_listing__is_confirmed_lux + subq_8.metric_time__day + , subq_12.listing__lux_listing__is_confirmed_lux diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multihop_node__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multihop_node__plan0.sql index a2cfac78b0..0743579296 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multihop_node__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multihop_node__plan0.sql @@ -1,511 +1,317 @@ -- Compute Metrics via Expressions SELECT - subq_12.account_id__customer_id__customer_name - , subq_12.txn_count + subq_8.account_id__customer_id__customer_name + , subq_8.txn_count FROM ( -- Aggregate Measures SELECT - subq_11.account_id__customer_id__customer_name - , SUM(subq_11.txn_count) AS txn_count + subq_7.account_id__customer_id__customer_name + , SUM(subq_7.txn_count) AS txn_count FROM ( + -- Join Standard Outputs -- Pass Only Elements: ['txn_count', 'account_id__customer_id__customer_name'] SELECT - subq_10.account_id__customer_id__customer_name - , subq_10.txn_count + subq_1.txn_count AS txn_count FROM ( + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['txn_count', 'ds_partitioned__day', 'account_id'] + SELECT + subq_0.ds_partitioned__day + , subq_0.account_id + , subq_0.txn_count + FROM ( + -- Read Elements From Semantic Model 'account_month_txns' + SELECT + account_month_txns_src_22000.txn_count + , DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_doy + , DATE_TRUNC('day', account_month_txns_src_22000.ds) AS ds__day + , DATE_TRUNC('week', account_month_txns_src_22000.ds) AS ds__week + , DATE_TRUNC('month', account_month_txns_src_22000.ds) AS ds__month + , DATE_TRUNC('quarter', account_month_txns_src_22000.ds) AS ds__quarter + , DATE_TRUNC('year', account_month_txns_src_22000.ds) AS ds__year + , EXTRACT(year FROM account_month_txns_src_22000.ds) AS ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_22000.ds) AS ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_22000.ds) AS ds__extract_month + , EXTRACT(day FROM account_month_txns_src_22000.ds) AS ds__extract_day + , EXTRACT(isodow FROM account_month_txns_src_22000.ds) AS ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_22000.ds) AS ds__extract_doy + , account_month_txns_src_22000.account_month + , DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__day + , DATE_TRUNC('week', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(day FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(isodow FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , DATE_TRUNC('day', account_month_txns_src_22000.ds) AS account_id__ds__day + , DATE_TRUNC('week', account_month_txns_src_22000.ds) AS account_id__ds__week + , DATE_TRUNC('month', account_month_txns_src_22000.ds) AS account_id__ds__month + , DATE_TRUNC('quarter', account_month_txns_src_22000.ds) AS account_id__ds__quarter + , DATE_TRUNC('year', account_month_txns_src_22000.ds) AS account_id__ds__year + , EXTRACT(year FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_year + , EXTRACT(quarter FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_quarter + , EXTRACT(month FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_month + , EXTRACT(day FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_day + , EXTRACT(isodow FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_dow + , EXTRACT(doy FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_doy + , account_month_txns_src_22000.account_month AS account_id__account_month + , account_month_txns_src_22000.account_id + FROM ***************************.account_month_txns account_month_txns_src_22000 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( -- Join Standard Outputs + -- Pass Only Elements: ['customer_id__customer_name', 'ds_partitioned__day', 'account_id'] SELECT - subq_2.ds_partitioned__day AS ds_partitioned__day - , subq_9.ds_partitioned__day AS account_id__ds_partitioned__day - , subq_2.account_id AS account_id - , subq_9.customer_id__customer_name AS account_id__customer_id__customer_name - , subq_2.txn_count AS txn_count + subq_3.ds_partitioned__day AS ds_partitioned__day + , subq_3.account_id AS account_id FROM ( - -- Pass Only Elements: ['txn_count', 'ds_partitioned__day', 'account_id'] + -- Metric Time Dimension 'ds_partitioned' SELECT - subq_1.ds_partitioned__day - , subq_1.account_id - , subq_1.txn_count + 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.account_id__ds_partitioned__day + , subq_2.account_id__ds_partitioned__week + , subq_2.account_id__ds_partitioned__month + , subq_2.account_id__ds_partitioned__quarter + , subq_2.account_id__ds_partitioned__year + , subq_2.account_id__ds_partitioned__extract_year + , subq_2.account_id__ds_partitioned__extract_quarter + , subq_2.account_id__ds_partitioned__extract_month + , subq_2.account_id__ds_partitioned__extract_day + , subq_2.account_id__ds_partitioned__extract_dow + , subq_2.account_id__ds_partitioned__extract_doy + , subq_2.bridge_account__ds_partitioned__day + , subq_2.bridge_account__ds_partitioned__week + , subq_2.bridge_account__ds_partitioned__month + , subq_2.bridge_account__ds_partitioned__quarter + , subq_2.bridge_account__ds_partitioned__year + , subq_2.bridge_account__ds_partitioned__extract_year + , subq_2.bridge_account__ds_partitioned__extract_quarter + , subq_2.bridge_account__ds_partitioned__extract_month + , subq_2.bridge_account__ds_partitioned__extract_day + , subq_2.bridge_account__ds_partitioned__extract_dow + , subq_2.bridge_account__ds_partitioned__extract_doy + , subq_2.ds_partitioned__day AS metric_time__day + , subq_2.ds_partitioned__week AS metric_time__week + , subq_2.ds_partitioned__month AS metric_time__month + , subq_2.ds_partitioned__quarter AS metric_time__quarter + , subq_2.ds_partitioned__year AS metric_time__year + , subq_2.ds_partitioned__extract_year AS metric_time__extract_year + , subq_2.ds_partitioned__extract_quarter AS metric_time__extract_quarter + , subq_2.ds_partitioned__extract_month AS metric_time__extract_month + , subq_2.ds_partitioned__extract_day AS metric_time__extract_day + , subq_2.ds_partitioned__extract_dow AS metric_time__extract_dow + , subq_2.ds_partitioned__extract_doy AS metric_time__extract_doy + , subq_2.account_id + , subq_2.customer_id + , subq_2.account_id__customer_id + , subq_2.bridge_account__account_id + , subq_2.bridge_account__customer_id + , subq_2.extra_dim + , subq_2.account_id__extra_dim + , subq_2.bridge_account__extra_dim + , subq_2.account_customer_combos FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bridge_table' SELECT - subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.account_id__ds_partitioned__day - , subq_0.account_id__ds_partitioned__week - , subq_0.account_id__ds_partitioned__month - , subq_0.account_id__ds_partitioned__quarter - , subq_0.account_id__ds_partitioned__year - , subq_0.account_id__ds_partitioned__extract_year - , subq_0.account_id__ds_partitioned__extract_quarter - , subq_0.account_id__ds_partitioned__extract_month - , subq_0.account_id__ds_partitioned__extract_day - , subq_0.account_id__ds_partitioned__extract_dow - , subq_0.account_id__ds_partitioned__extract_doy - , subq_0.account_id__ds__day - , subq_0.account_id__ds__week - , subq_0.account_id__ds__month - , subq_0.account_id__ds__quarter - , subq_0.account_id__ds__year - , subq_0.account_id__ds__extract_year - , subq_0.account_id__ds__extract_quarter - , subq_0.account_id__ds__extract_month - , subq_0.account_id__ds__extract_day - , subq_0.account_id__ds__extract_dow - , subq_0.account_id__ds__extract_doy - , subq_0.ds__day AS metric_time__day - , subq_0.ds__week AS metric_time__week - , subq_0.ds__month AS metric_time__month - , subq_0.ds__quarter AS metric_time__quarter - , subq_0.ds__year AS metric_time__year - , subq_0.ds__extract_year AS metric_time__extract_year - , subq_0.ds__extract_quarter AS metric_time__extract_quarter - , subq_0.ds__extract_month AS metric_time__extract_month - , subq_0.ds__extract_day AS metric_time__extract_day - , subq_0.ds__extract_dow AS metric_time__extract_dow - , subq_0.ds__extract_doy AS metric_time__extract_doy - , subq_0.account_id - , subq_0.account_month - , subq_0.account_id__account_month - , subq_0.txn_count - FROM ( - -- Read Elements From Semantic Model 'account_month_txns' - SELECT - account_month_txns_src_22000.txn_count - , DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM account_month_txns_src_22000.ds_partitioned) AS ds_partitioned__extract_doy - , DATE_TRUNC('day', account_month_txns_src_22000.ds) AS ds__day - , DATE_TRUNC('week', account_month_txns_src_22000.ds) AS ds__week - , DATE_TRUNC('month', account_month_txns_src_22000.ds) AS ds__month - , DATE_TRUNC('quarter', account_month_txns_src_22000.ds) AS ds__quarter - , DATE_TRUNC('year', account_month_txns_src_22000.ds) AS ds__year - , EXTRACT(year FROM account_month_txns_src_22000.ds) AS ds__extract_year - , EXTRACT(quarter FROM account_month_txns_src_22000.ds) AS ds__extract_quarter - , EXTRACT(month FROM account_month_txns_src_22000.ds) AS ds__extract_month - , EXTRACT(day FROM account_month_txns_src_22000.ds) AS ds__extract_day - , EXTRACT(isodow FROM account_month_txns_src_22000.ds) AS ds__extract_dow - , EXTRACT(doy FROM account_month_txns_src_22000.ds) AS ds__extract_doy - , account_month_txns_src_22000.account_month - , DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__day - , DATE_TRUNC('week', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__week - , DATE_TRUNC('month', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__month - , DATE_TRUNC('quarter', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__quarter - , DATE_TRUNC('year', account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__year - , EXTRACT(year FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_year - , EXTRACT(quarter FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_quarter - , EXTRACT(month FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_month - , EXTRACT(day FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_day - , EXTRACT(isodow FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_dow - , EXTRACT(doy FROM account_month_txns_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_doy - , DATE_TRUNC('day', account_month_txns_src_22000.ds) AS account_id__ds__day - , DATE_TRUNC('week', account_month_txns_src_22000.ds) AS account_id__ds__week - , DATE_TRUNC('month', account_month_txns_src_22000.ds) AS account_id__ds__month - , DATE_TRUNC('quarter', account_month_txns_src_22000.ds) AS account_id__ds__quarter - , DATE_TRUNC('year', account_month_txns_src_22000.ds) AS account_id__ds__year - , EXTRACT(year FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_year - , EXTRACT(quarter FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_quarter - , EXTRACT(month FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_month - , EXTRACT(day FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_day - , EXTRACT(isodow FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_dow - , EXTRACT(doy FROM account_month_txns_src_22000.ds) AS account_id__ds__extract_doy - , account_month_txns_src_22000.account_month AS account_id__account_month - , account_month_txns_src_22000.account_id - FROM ***************************.account_month_txns account_month_txns_src_22000 - ) subq_0 - ) subq_1 - ) subq_2 + account_id || customer_id AS account_customer_combos + , bridge_table_src_22000.extra_dim + , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_doy + , bridge_table_src_22000.extra_dim AS account_id__extra_dim + , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_day + , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_doy + , bridge_table_src_22000.extra_dim AS bridge_account__extra_dim + , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__day + , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__week + , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__month + , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__quarter + , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__year + , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_year + , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter + , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_month + , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_day + , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow + , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy + , bridge_table_src_22000.account_id + , bridge_table_src_22000.customer_id + , bridge_table_src_22000.customer_id AS account_id__customer_id + , bridge_table_src_22000.account_id AS bridge_account__account_id + , bridge_table_src_22000.customer_id AS bridge_account__customer_id + FROM ***************************.bridge_table bridge_table_src_22000 + ) subq_2 + ) subq_3 LEFT OUTER JOIN ( - -- Pass Only Elements: ['customer_id__customer_name', 'ds_partitioned__day', 'account_id'] + -- Metric Time Dimension 'ds_partitioned' + -- Pass Only Elements: [ + -- 'customer_name', + -- 'customer_atomic_weight', + -- 'customer_id__customer_name', + -- 'customer_id__customer_atomic_weight', + -- 'ds_partitioned__day', + -- 'ds_partitioned__week', + -- 'ds_partitioned__month', + -- 'ds_partitioned__quarter', + -- 'ds_partitioned__year', + -- 'ds_partitioned__extract_year', + -- 'ds_partitioned__extract_quarter', + -- 'ds_partitioned__extract_month', + -- 'ds_partitioned__extract_day', + -- 'ds_partitioned__extract_dow', + -- 'ds_partitioned__extract_doy', + -- 'customer_id__ds_partitioned__day', + -- 'customer_id__ds_partitioned__week', + -- 'customer_id__ds_partitioned__month', + -- 'customer_id__ds_partitioned__quarter', + -- 'customer_id__ds_partitioned__year', + -- 'customer_id__ds_partitioned__extract_year', + -- 'customer_id__ds_partitioned__extract_quarter', + -- 'customer_id__ds_partitioned__extract_month', + -- 'customer_id__ds_partitioned__extract_day', + -- 'customer_id__ds_partitioned__extract_dow', + -- 'customer_id__ds_partitioned__extract_doy', + -- 'metric_time__day', + -- 'metric_time__week', + -- 'metric_time__month', + -- 'metric_time__quarter', + -- 'metric_time__year', + -- 'metric_time__extract_year', + -- 'metric_time__extract_quarter', + -- 'metric_time__extract_month', + -- 'metric_time__extract_day', + -- 'metric_time__extract_dow', + -- 'metric_time__extract_doy', + -- 'customer_id', + -- ] SELECT - subq_8.ds_partitioned__day - , subq_8.account_id - , subq_8.customer_id__customer_name + 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.customer_id__ds_partitioned__day + , subq_4.customer_id__ds_partitioned__week + , subq_4.customer_id__ds_partitioned__month + , subq_4.customer_id__ds_partitioned__quarter + , subq_4.customer_id__ds_partitioned__year + , subq_4.customer_id__ds_partitioned__extract_year + , subq_4.customer_id__ds_partitioned__extract_quarter + , subq_4.customer_id__ds_partitioned__extract_month + , subq_4.customer_id__ds_partitioned__extract_day + , subq_4.customer_id__ds_partitioned__extract_dow + , subq_4.customer_id__ds_partitioned__extract_doy + , subq_4.ds_partitioned__day AS metric_time__day + , subq_4.ds_partitioned__week AS metric_time__week + , subq_4.ds_partitioned__month AS metric_time__month + , subq_4.ds_partitioned__quarter AS metric_time__quarter + , subq_4.ds_partitioned__year AS metric_time__year + , subq_4.ds_partitioned__extract_year AS metric_time__extract_year + , subq_4.ds_partitioned__extract_quarter AS metric_time__extract_quarter + , subq_4.ds_partitioned__extract_month AS metric_time__extract_month + , subq_4.ds_partitioned__extract_day AS metric_time__extract_day + , subq_4.ds_partitioned__extract_dow AS metric_time__extract_dow + , subq_4.ds_partitioned__extract_doy AS metric_time__extract_doy + , subq_4.customer_id + , subq_4.customer_name + , subq_4.customer_atomic_weight + , subq_4.customer_id__customer_name + , subq_4.customer_id__customer_atomic_weight FROM ( - -- Join Standard Outputs + -- Read Elements From Semantic Model 'customer_table' SELECT - subq_4.ds_partitioned__day AS ds_partitioned__day - , subq_4.ds_partitioned__week AS ds_partitioned__week - , subq_4.ds_partitioned__month AS ds_partitioned__month - , subq_4.ds_partitioned__quarter AS ds_partitioned__quarter - , subq_4.ds_partitioned__year AS ds_partitioned__year - , subq_4.ds_partitioned__extract_year AS ds_partitioned__extract_year - , subq_4.ds_partitioned__extract_quarter AS ds_partitioned__extract_quarter - , subq_4.ds_partitioned__extract_month AS ds_partitioned__extract_month - , subq_4.ds_partitioned__extract_day AS ds_partitioned__extract_day - , subq_4.ds_partitioned__extract_dow AS ds_partitioned__extract_dow - , subq_4.ds_partitioned__extract_doy AS ds_partitioned__extract_doy - , subq_4.account_id__ds_partitioned__day AS account_id__ds_partitioned__day - , subq_4.account_id__ds_partitioned__week AS account_id__ds_partitioned__week - , subq_4.account_id__ds_partitioned__month AS account_id__ds_partitioned__month - , subq_4.account_id__ds_partitioned__quarter AS account_id__ds_partitioned__quarter - , subq_4.account_id__ds_partitioned__year AS account_id__ds_partitioned__year - , subq_4.account_id__ds_partitioned__extract_year AS account_id__ds_partitioned__extract_year - , subq_4.account_id__ds_partitioned__extract_quarter AS account_id__ds_partitioned__extract_quarter - , subq_4.account_id__ds_partitioned__extract_month AS account_id__ds_partitioned__extract_month - , subq_4.account_id__ds_partitioned__extract_day AS account_id__ds_partitioned__extract_day - , subq_4.account_id__ds_partitioned__extract_dow AS account_id__ds_partitioned__extract_dow - , subq_4.account_id__ds_partitioned__extract_doy AS account_id__ds_partitioned__extract_doy - , subq_4.bridge_account__ds_partitioned__day AS bridge_account__ds_partitioned__day - , subq_4.bridge_account__ds_partitioned__week AS bridge_account__ds_partitioned__week - , subq_4.bridge_account__ds_partitioned__month AS bridge_account__ds_partitioned__month - , subq_4.bridge_account__ds_partitioned__quarter AS bridge_account__ds_partitioned__quarter - , subq_4.bridge_account__ds_partitioned__year AS bridge_account__ds_partitioned__year - , subq_4.bridge_account__ds_partitioned__extract_year AS bridge_account__ds_partitioned__extract_year - , subq_4.bridge_account__ds_partitioned__extract_quarter AS bridge_account__ds_partitioned__extract_quarter - , subq_4.bridge_account__ds_partitioned__extract_month AS bridge_account__ds_partitioned__extract_month - , subq_4.bridge_account__ds_partitioned__extract_day AS bridge_account__ds_partitioned__extract_day - , subq_4.bridge_account__ds_partitioned__extract_dow AS bridge_account__ds_partitioned__extract_dow - , subq_4.bridge_account__ds_partitioned__extract_doy AS bridge_account__ds_partitioned__extract_doy - , subq_4.metric_time__day AS metric_time__day - , subq_4.metric_time__week AS metric_time__week - , subq_4.metric_time__month AS metric_time__month - , subq_4.metric_time__quarter AS metric_time__quarter - , subq_4.metric_time__year AS metric_time__year - , subq_4.metric_time__extract_year AS metric_time__extract_year - , subq_4.metric_time__extract_quarter AS metric_time__extract_quarter - , subq_4.metric_time__extract_month AS metric_time__extract_month - , 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_7.ds_partitioned__day AS customer_id__ds_partitioned__day - , subq_7.ds_partitioned__week AS customer_id__ds_partitioned__week - , subq_7.ds_partitioned__month AS customer_id__ds_partitioned__month - , subq_7.ds_partitioned__quarter AS customer_id__ds_partitioned__quarter - , subq_7.ds_partitioned__year AS customer_id__ds_partitioned__year - , subq_7.ds_partitioned__extract_year AS customer_id__ds_partitioned__extract_year - , subq_7.ds_partitioned__extract_quarter AS customer_id__ds_partitioned__extract_quarter - , subq_7.ds_partitioned__extract_month AS customer_id__ds_partitioned__extract_month - , subq_7.ds_partitioned__extract_day AS customer_id__ds_partitioned__extract_day - , subq_7.ds_partitioned__extract_dow AS customer_id__ds_partitioned__extract_dow - , subq_7.ds_partitioned__extract_doy AS customer_id__ds_partitioned__extract_doy - , subq_7.metric_time__day AS customer_id__metric_time__day - , subq_7.metric_time__week AS customer_id__metric_time__week - , subq_7.metric_time__month AS customer_id__metric_time__month - , subq_7.metric_time__quarter AS customer_id__metric_time__quarter - , subq_7.metric_time__year AS customer_id__metric_time__year - , subq_7.metric_time__extract_year AS customer_id__metric_time__extract_year - , subq_7.metric_time__extract_quarter AS customer_id__metric_time__extract_quarter - , subq_7.metric_time__extract_month AS customer_id__metric_time__extract_month - , subq_7.metric_time__extract_day AS customer_id__metric_time__extract_day - , subq_7.metric_time__extract_dow AS customer_id__metric_time__extract_dow - , subq_7.metric_time__extract_doy AS customer_id__metric_time__extract_doy - , subq_4.account_id AS account_id - , subq_4.customer_id AS customer_id - , subq_4.account_id__customer_id AS account_id__customer_id - , subq_4.bridge_account__account_id AS bridge_account__account_id - , subq_4.bridge_account__customer_id AS bridge_account__customer_id - , subq_4.extra_dim AS extra_dim - , subq_4.account_id__extra_dim AS account_id__extra_dim - , subq_4.bridge_account__extra_dim AS bridge_account__extra_dim - , subq_7.customer_name AS customer_id__customer_name - , subq_7.customer_atomic_weight AS customer_id__customer_atomic_weight - , subq_4.account_customer_combos AS account_customer_combos - FROM ( - -- Metric Time Dimension 'ds_partitioned' - SELECT - subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.account_id__ds_partitioned__day - , subq_3.account_id__ds_partitioned__week - , subq_3.account_id__ds_partitioned__month - , subq_3.account_id__ds_partitioned__quarter - , subq_3.account_id__ds_partitioned__year - , subq_3.account_id__ds_partitioned__extract_year - , subq_3.account_id__ds_partitioned__extract_quarter - , subq_3.account_id__ds_partitioned__extract_month - , subq_3.account_id__ds_partitioned__extract_day - , subq_3.account_id__ds_partitioned__extract_dow - , subq_3.account_id__ds_partitioned__extract_doy - , subq_3.bridge_account__ds_partitioned__day - , subq_3.bridge_account__ds_partitioned__week - , subq_3.bridge_account__ds_partitioned__month - , subq_3.bridge_account__ds_partitioned__quarter - , subq_3.bridge_account__ds_partitioned__year - , subq_3.bridge_account__ds_partitioned__extract_year - , subq_3.bridge_account__ds_partitioned__extract_quarter - , subq_3.bridge_account__ds_partitioned__extract_month - , subq_3.bridge_account__ds_partitioned__extract_day - , subq_3.bridge_account__ds_partitioned__extract_dow - , subq_3.bridge_account__ds_partitioned__extract_doy - , subq_3.ds_partitioned__day AS metric_time__day - , subq_3.ds_partitioned__week AS metric_time__week - , subq_3.ds_partitioned__month AS metric_time__month - , subq_3.ds_partitioned__quarter AS metric_time__quarter - , subq_3.ds_partitioned__year AS metric_time__year - , subq_3.ds_partitioned__extract_year AS metric_time__extract_year - , subq_3.ds_partitioned__extract_quarter AS metric_time__extract_quarter - , subq_3.ds_partitioned__extract_month AS metric_time__extract_month - , subq_3.ds_partitioned__extract_day AS metric_time__extract_day - , subq_3.ds_partitioned__extract_dow AS metric_time__extract_dow - , subq_3.ds_partitioned__extract_doy AS metric_time__extract_doy - , subq_3.account_id - , subq_3.customer_id - , subq_3.account_id__customer_id - , subq_3.bridge_account__account_id - , subq_3.bridge_account__customer_id - , subq_3.extra_dim - , subq_3.account_id__extra_dim - , subq_3.bridge_account__extra_dim - , subq_3.account_customer_combos - FROM ( - -- Read Elements From Semantic Model 'bridge_table' - SELECT - account_id || customer_id AS account_customer_combos - , bridge_table_src_22000.extra_dim - , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS ds_partitioned__extract_doy - , bridge_table_src_22000.extra_dim AS account_id__extra_dim - , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_day - , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS account_id__ds_partitioned__extract_doy - , bridge_table_src_22000.extra_dim AS bridge_account__extra_dim - , DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__day - , DATE_TRUNC('week', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__week - , DATE_TRUNC('month', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__month - , DATE_TRUNC('quarter', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__quarter - , DATE_TRUNC('year', bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__year - , EXTRACT(year FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_year - , EXTRACT(quarter FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_quarter - , EXTRACT(month FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_month - , EXTRACT(day FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_day - , EXTRACT(isodow FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_dow - , EXTRACT(doy FROM bridge_table_src_22000.ds_partitioned) AS bridge_account__ds_partitioned__extract_doy - , bridge_table_src_22000.account_id - , bridge_table_src_22000.customer_id - , bridge_table_src_22000.customer_id AS account_id__customer_id - , bridge_table_src_22000.account_id AS bridge_account__account_id - , bridge_table_src_22000.customer_id AS bridge_account__customer_id - FROM ***************************.bridge_table bridge_table_src_22000 - ) subq_3 - ) subq_4 - LEFT OUTER JOIN ( - -- Pass Only Elements: [ - -- 'customer_name', - -- 'customer_atomic_weight', - -- 'customer_id__customer_name', - -- 'customer_id__customer_atomic_weight', - -- 'ds_partitioned__day', - -- 'ds_partitioned__week', - -- 'ds_partitioned__month', - -- 'ds_partitioned__quarter', - -- 'ds_partitioned__year', - -- 'ds_partitioned__extract_year', - -- 'ds_partitioned__extract_quarter', - -- 'ds_partitioned__extract_month', - -- 'ds_partitioned__extract_day', - -- 'ds_partitioned__extract_dow', - -- 'ds_partitioned__extract_doy', - -- 'customer_id__ds_partitioned__day', - -- 'customer_id__ds_partitioned__week', - -- 'customer_id__ds_partitioned__month', - -- 'customer_id__ds_partitioned__quarter', - -- 'customer_id__ds_partitioned__year', - -- 'customer_id__ds_partitioned__extract_year', - -- 'customer_id__ds_partitioned__extract_quarter', - -- 'customer_id__ds_partitioned__extract_month', - -- 'customer_id__ds_partitioned__extract_day', - -- 'customer_id__ds_partitioned__extract_dow', - -- 'customer_id__ds_partitioned__extract_doy', - -- 'metric_time__day', - -- 'metric_time__week', - -- 'metric_time__month', - -- 'metric_time__quarter', - -- 'metric_time__year', - -- 'metric_time__extract_year', - -- 'metric_time__extract_quarter', - -- 'metric_time__extract_month', - -- 'metric_time__extract_day', - -- 'metric_time__extract_dow', - -- 'metric_time__extract_doy', - -- 'customer_id', - -- ] - SELECT - 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.customer_id__ds_partitioned__day - , subq_6.customer_id__ds_partitioned__week - , subq_6.customer_id__ds_partitioned__month - , subq_6.customer_id__ds_partitioned__quarter - , subq_6.customer_id__ds_partitioned__year - , subq_6.customer_id__ds_partitioned__extract_year - , subq_6.customer_id__ds_partitioned__extract_quarter - , subq_6.customer_id__ds_partitioned__extract_month - , subq_6.customer_id__ds_partitioned__extract_day - , subq_6.customer_id__ds_partitioned__extract_dow - , subq_6.customer_id__ds_partitioned__extract_doy - , subq_6.metric_time__day - , subq_6.metric_time__week - , subq_6.metric_time__month - , subq_6.metric_time__quarter - , subq_6.metric_time__year - , subq_6.metric_time__extract_year - , subq_6.metric_time__extract_quarter - , subq_6.metric_time__extract_month - , subq_6.metric_time__extract_day - , subq_6.metric_time__extract_dow - , subq_6.metric_time__extract_doy - , subq_6.customer_id - , subq_6.customer_name - , subq_6.customer_atomic_weight - , subq_6.customer_id__customer_name - , subq_6.customer_id__customer_atomic_weight - FROM ( - -- Metric Time Dimension 'ds_partitioned' - SELECT - 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.customer_id__ds_partitioned__day - , subq_5.customer_id__ds_partitioned__week - , subq_5.customer_id__ds_partitioned__month - , subq_5.customer_id__ds_partitioned__quarter - , subq_5.customer_id__ds_partitioned__year - , subq_5.customer_id__ds_partitioned__extract_year - , subq_5.customer_id__ds_partitioned__extract_quarter - , subq_5.customer_id__ds_partitioned__extract_month - , subq_5.customer_id__ds_partitioned__extract_day - , subq_5.customer_id__ds_partitioned__extract_dow - , subq_5.customer_id__ds_partitioned__extract_doy - , subq_5.ds_partitioned__day AS metric_time__day - , subq_5.ds_partitioned__week AS metric_time__week - , subq_5.ds_partitioned__month AS metric_time__month - , subq_5.ds_partitioned__quarter AS metric_time__quarter - , subq_5.ds_partitioned__year AS metric_time__year - , subq_5.ds_partitioned__extract_year AS metric_time__extract_year - , subq_5.ds_partitioned__extract_quarter AS metric_time__extract_quarter - , subq_5.ds_partitioned__extract_month AS metric_time__extract_month - , subq_5.ds_partitioned__extract_day AS metric_time__extract_day - , subq_5.ds_partitioned__extract_dow AS metric_time__extract_dow - , subq_5.ds_partitioned__extract_doy AS metric_time__extract_doy - , subq_5.customer_id - , subq_5.customer_name - , subq_5.customer_atomic_weight - , subq_5.customer_id__customer_name - , subq_5.customer_id__customer_atomic_weight - , subq_5.customers - FROM ( - -- Read Elements From Semantic Model 'customer_table' - SELECT - 1 AS customers - , customer_table_src_22000.customer_name - , customer_table_src_22000.customer_atomic_weight - , DATE_TRUNC('day', customer_table_src_22000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', customer_table_src_22000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', customer_table_src_22000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', customer_table_src_22000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', customer_table_src_22000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_doy - , customer_table_src_22000.customer_name AS customer_id__customer_name - , customer_table_src_22000.customer_atomic_weight AS customer_id__customer_atomic_weight - , DATE_TRUNC('day', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__day - , DATE_TRUNC('week', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__week - , DATE_TRUNC('month', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__month - , DATE_TRUNC('quarter', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__quarter - , DATE_TRUNC('year', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__year - , EXTRACT(year FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_year - , EXTRACT(quarter FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_quarter - , EXTRACT(month FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_month - , EXTRACT(day FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_day - , EXTRACT(isodow FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_dow - , EXTRACT(doy FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_doy - , customer_table_src_22000.customer_id - FROM ***************************.customer_table customer_table_src_22000 - ) subq_5 - ) subq_6 - ) subq_7 - ON - ( - subq_4.customer_id = subq_7.customer_id - ) AND ( - subq_4.ds_partitioned__day = subq_7.ds_partitioned__day - ) - ) subq_8 - ) subq_9 + 1 AS customers + , customer_table_src_22000.customer_name + , customer_table_src_22000.customer_atomic_weight + , DATE_TRUNC('day', customer_table_src_22000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', customer_table_src_22000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', customer_table_src_22000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', customer_table_src_22000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', customer_table_src_22000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM customer_table_src_22000.ds_partitioned) AS ds_partitioned__extract_doy + , customer_table_src_22000.customer_name AS customer_id__customer_name + , customer_table_src_22000.customer_atomic_weight AS customer_id__customer_atomic_weight + , DATE_TRUNC('day', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__day + , DATE_TRUNC('week', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__week + , DATE_TRUNC('month', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__month + , DATE_TRUNC('quarter', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__quarter + , DATE_TRUNC('year', customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__year + , EXTRACT(year FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_year + , EXTRACT(quarter FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_quarter + , EXTRACT(month FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_month + , EXTRACT(day FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_day + , EXTRACT(isodow FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_dow + , EXTRACT(doy FROM customer_table_src_22000.ds_partitioned) AS customer_id__ds_partitioned__extract_doy + , customer_table_src_22000.customer_id + FROM ***************************.customer_table customer_table_src_22000 + ) subq_4 + ) subq_5 ON ( - subq_2.account_id = subq_9.account_id + subq_3.customer_id = subq_5.customer_id ) AND ( - subq_2.ds_partitioned__day = subq_9.ds_partitioned__day + subq_3.ds_partitioned__day = subq_5.ds_partitioned__day ) - ) subq_10 - ) subq_11 + ) subq_6 + ON + ( + subq_1.account_id = subq_6.account_id + ) AND ( + subq_1.ds_partitioned__day = subq_6.ds_partitioned__day + ) + ) subq_7 GROUP BY - subq_11.account_id__customer_id__customer_name -) subq_12 + subq_7.account_id__customer_id__customer_name +) subq_8 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multihop_node__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multihop_node__plan0_optimized.sql index 13473156ca..c324af1ff2 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multihop_node__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multihop_node__plan0_optimized.sql @@ -3,7 +3,7 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - subq_22.customer_id__customer_name AS account_id__customer_id__customer_name + subq_16.account_id__customer_id__customer_name AS account_id__customer_id__customer_name , SUM(account_month_txns_src_22000.txn_count) AS txn_count FROM ***************************.account_month_txns account_month_txns_src_22000 LEFT OUTER JOIN ( @@ -12,7 +12,6 @@ LEFT OUTER JOIN ( SELECT DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) AS ds_partitioned__day , bridge_table_src_22000.account_id AS account_id - , customer_table_src_22000.customer_name AS customer_id__customer_name FROM ***************************.bridge_table bridge_table_src_22000 LEFT OUTER JOIN ***************************.customer_table customer_table_src_22000 @@ -22,12 +21,12 @@ LEFT OUTER JOIN ( ) AND ( DATE_TRUNC('day', bridge_table_src_22000.ds_partitioned) = DATE_TRUNC('day', customer_table_src_22000.ds_partitioned) ) -) subq_22 +) subq_15 ON ( - account_month_txns_src_22000.account_id = subq_22.account_id + account_month_txns_src_22000.account_id = subq_15.account_id ) AND ( - DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) = subq_22.ds_partitioned__day + DATE_TRUNC('day', account_month_txns_src_22000.ds_partitioned) = subq_15.ds_partitioned__day ) GROUP BY - subq_22.customer_id__customer_name + subq_16.account_id__customer_id__customer_name diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multiple_metrics_no_dimensions__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multiple_metrics_no_dimensions__plan0.sql index 7eb505d9c1..ef12a47267 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multiple_metrics_no_dimensions__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multiple_metrics_no_dimensions__plan0.sql @@ -1,536 +1,365 @@ -- Combine Aggregated Outputs SELECT - MAX(subq_5.bookings) AS bookings - , MAX(subq_11.listings) AS listings + MAX(subq_4.bookings) AS bookings + , MAX(subq_9.listings) AS listings FROM ( -- Compute Metrics via Expressions SELECT - subq_4.bookings + subq_3.bookings FROM ( -- Aggregate Measures SELECT - SUM(subq_3.bookings) AS bookings + SUM(subq_2.bookings) AS bookings FROM ( + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] -- Pass Only Elements: ['bookings',] SELECT - subq_2.bookings + subq_1.bookings FROM ( - -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] + -- Metric Time Dimension 'ds' SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.ds_partitioned__day - , subq_1.ds_partitioned__week - , subq_1.ds_partitioned__month - , subq_1.ds_partitioned__quarter - , subq_1.ds_partitioned__year - , subq_1.ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy - , subq_1.paid_at__day - , subq_1.paid_at__week - , subq_1.paid_at__month - , subq_1.paid_at__quarter - , subq_1.paid_at__year - , subq_1.paid_at__extract_year - , subq_1.paid_at__extract_quarter - , subq_1.paid_at__extract_month - , subq_1.paid_at__extract_day - , subq_1.paid_at__extract_dow - , subq_1.paid_at__extract_doy - , subq_1.booking__ds__day - , subq_1.booking__ds__week - , subq_1.booking__ds__month - , subq_1.booking__ds__quarter - , subq_1.booking__ds__year - , subq_1.booking__ds__extract_year - , subq_1.booking__ds__extract_quarter - , subq_1.booking__ds__extract_month - , subq_1.booking__ds__extract_day - , subq_1.booking__ds__extract_dow - , subq_1.booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day - , subq_1.booking__paid_at__week - , subq_1.booking__paid_at__month - , subq_1.booking__paid_at__quarter - , subq_1.booking__paid_at__year - , subq_1.booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.listing - , subq_1.guest - , subq_1.host - , subq_1.booking__listing - , subq_1.booking__guest - , subq_1.booking__host - , subq_1.is_instant - , subq_1.booking__is_instant - , subq_1.bookings - , subq_1.instant_bookings - , subq_1.booking_value - , subq_1.max_booking_value - , subq_1.min_booking_value - , subq_1.bookers - , subq_1.average_booking_value - , subq_1.referred_bookings - , subq_1.median_booking_value - , subq_1.booking_value_p99 - , subq_1.discrete_booking_value_p99 - , subq_1.approximate_continuous_booking_value_p99 - , subq_1.approximate_discrete_booking_value_p99 + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' - ) subq_2 - ) subq_3 - ) subq_4 -) subq_5 + 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 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' + ) subq_2 + ) subq_3 +) subq_4 CROSS JOIN ( -- Compute Metrics via Expressions SELECT - subq_10.listings + subq_8.listings FROM ( -- Aggregate Measures SELECT - SUM(subq_9.listings) AS listings + SUM(subq_7.listings) AS listings FROM ( + -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] -- Pass Only Elements: ['listings',] SELECT - subq_8.listings + subq_6.listings FROM ( - -- Constrain Time Range to [2020-01-01T00:00:00, 2020-01-01T00:00:00] + -- 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.created_at__day - , subq_7.created_at__week - , subq_7.created_at__month - , subq_7.created_at__quarter - , subq_7.created_at__year - , subq_7.created_at__extract_year - , subq_7.created_at__extract_quarter - , subq_7.created_at__extract_month - , subq_7.created_at__extract_day - , subq_7.created_at__extract_dow - , subq_7.created_at__extract_doy - , subq_7.listing__ds__day - , subq_7.listing__ds__week - , subq_7.listing__ds__month - , subq_7.listing__ds__quarter - , subq_7.listing__ds__year - , subq_7.listing__ds__extract_year - , subq_7.listing__ds__extract_quarter - , subq_7.listing__ds__extract_month - , subq_7.listing__ds__extract_day - , subq_7.listing__ds__extract_dow - , subq_7.listing__ds__extract_doy - , subq_7.listing__created_at__day - , subq_7.listing__created_at__week - , subq_7.listing__created_at__month - , subq_7.listing__created_at__quarter - , subq_7.listing__created_at__year - , subq_7.listing__created_at__extract_year - , subq_7.listing__created_at__extract_quarter - , subq_7.listing__created_at__extract_month - , subq_7.listing__created_at__extract_day - , subq_7.listing__created_at__extract_dow - , subq_7.listing__created_at__extract_doy - , subq_7.metric_time__day - , subq_7.metric_time__week - , subq_7.metric_time__month - , subq_7.metric_time__quarter - , subq_7.metric_time__year - , subq_7.metric_time__extract_year - , subq_7.metric_time__extract_quarter - , subq_7.metric_time__extract_month - , subq_7.metric_time__extract_day - , subq_7.metric_time__extract_dow - , subq_7.metric_time__extract_doy - , subq_7.listing - , subq_7.user - , subq_7.listing__user - , subq_7.country_latest - , subq_7.is_lux_latest - , subq_7.capacity_latest - , subq_7.listing__country_latest - , subq_7.listing__is_lux_latest - , subq_7.listing__capacity_latest - , subq_7.listings - , subq_7.largest_listing - , subq_7.smallest_listing + 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.created_at__day + , subq_5.created_at__week + , subq_5.created_at__month + , subq_5.created_at__quarter + , subq_5.created_at__year + , subq_5.created_at__extract_year + , subq_5.created_at__extract_quarter + , subq_5.created_at__extract_month + , subq_5.created_at__extract_day + , subq_5.created_at__extract_dow + , subq_5.created_at__extract_doy + , subq_5.listing__ds__day + , subq_5.listing__ds__week + , subq_5.listing__ds__month + , subq_5.listing__ds__quarter + , subq_5.listing__ds__year + , subq_5.listing__ds__extract_year + , subq_5.listing__ds__extract_quarter + , subq_5.listing__ds__extract_month + , subq_5.listing__ds__extract_day + , subq_5.listing__ds__extract_dow + , subq_5.listing__ds__extract_doy + , subq_5.listing__created_at__day + , subq_5.listing__created_at__week + , subq_5.listing__created_at__month + , subq_5.listing__created_at__quarter + , subq_5.listing__created_at__year + , subq_5.listing__created_at__extract_year + , subq_5.listing__created_at__extract_quarter + , subq_5.listing__created_at__extract_month + , subq_5.listing__created_at__extract_day + , subq_5.listing__created_at__extract_dow + , subq_5.listing__created_at__extract_doy + , subq_5.ds__day AS metric_time__day + , subq_5.ds__week AS metric_time__week + , subq_5.ds__month AS metric_time__month + , subq_5.ds__quarter AS metric_time__quarter + , subq_5.ds__year AS metric_time__year + , subq_5.ds__extract_year AS metric_time__extract_year + , subq_5.ds__extract_quarter AS metric_time__extract_quarter + , subq_5.ds__extract_month AS metric_time__extract_month + , subq_5.ds__extract_day AS metric_time__extract_day + , subq_5.ds__extract_dow AS metric_time__extract_dow + , subq_5.ds__extract_doy AS metric_time__extract_doy + , subq_5.listing + , subq_5.user + , subq_5.listing__user + , subq_5.country_latest + , subq_5.is_lux_latest + , subq_5.capacity_latest + , subq_5.listing__country_latest + , subq_5.listing__is_lux_latest + , subq_5.listing__capacity_latest + , subq_5.listings + , subq_5.largest_listing + , subq_5.smallest_listing FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'listings_latest' SELECT - subq_6.ds__day - , subq_6.ds__week - , subq_6.ds__month - , subq_6.ds__quarter - , subq_6.ds__year - , subq_6.ds__extract_year - , subq_6.ds__extract_quarter - , subq_6.ds__extract_month - , subq_6.ds__extract_day - , subq_6.ds__extract_dow - , subq_6.ds__extract_doy - , subq_6.created_at__day - , subq_6.created_at__week - , subq_6.created_at__month - , subq_6.created_at__quarter - , subq_6.created_at__year - , subq_6.created_at__extract_year - , subq_6.created_at__extract_quarter - , subq_6.created_at__extract_month - , subq_6.created_at__extract_day - , subq_6.created_at__extract_dow - , subq_6.created_at__extract_doy - , subq_6.listing__ds__day - , subq_6.listing__ds__week - , subq_6.listing__ds__month - , subq_6.listing__ds__quarter - , subq_6.listing__ds__year - , subq_6.listing__ds__extract_year - , subq_6.listing__ds__extract_quarter - , subq_6.listing__ds__extract_month - , subq_6.listing__ds__extract_day - , subq_6.listing__ds__extract_dow - , subq_6.listing__ds__extract_doy - , subq_6.listing__created_at__day - , subq_6.listing__created_at__week - , subq_6.listing__created_at__month - , subq_6.listing__created_at__quarter - , subq_6.listing__created_at__year - , subq_6.listing__created_at__extract_year - , subq_6.listing__created_at__extract_quarter - , subq_6.listing__created_at__extract_month - , subq_6.listing__created_at__extract_day - , subq_6.listing__created_at__extract_dow - , subq_6.listing__created_at__extract_doy - , subq_6.ds__day AS metric_time__day - , subq_6.ds__week AS metric_time__week - , subq_6.ds__month AS metric_time__month - , subq_6.ds__quarter AS metric_time__quarter - , subq_6.ds__year AS metric_time__year - , subq_6.ds__extract_year AS metric_time__extract_year - , subq_6.ds__extract_quarter AS metric_time__extract_quarter - , subq_6.ds__extract_month AS metric_time__extract_month - , subq_6.ds__extract_day AS metric_time__extract_day - , subq_6.ds__extract_dow AS metric_time__extract_dow - , subq_6.ds__extract_doy AS metric_time__extract_doy - , subq_6.listing - , subq_6.user - , subq_6.listing__user - , subq_6.country_latest - , subq_6.is_lux_latest - , subq_6.capacity_latest - , subq_6.listing__country_latest - , subq_6.listing__is_lux_latest - , subq_6.listing__capacity_latest - , subq_6.listings - , subq_6.largest_listing - , subq_6.smallest_listing - FROM ( - -- Read Elements From Semantic Model 'listings_latest' - SELECT - 1 AS listings - , listings_latest_src_28000.capacity AS largest_listing - , listings_latest_src_28000.capacity AS smallest_listing - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy - , listings_latest_src_28000.country AS country_latest - , listings_latest_src_28000.is_lux AS is_lux_latest - , listings_latest_src_28000.capacity AS capacity_latest - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy - , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day - , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week - , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month - , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter - , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year - , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year - , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter - , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month - , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day - , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow - , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy - , listings_latest_src_28000.country AS listing__country_latest - , listings_latest_src_28000.is_lux AS listing__is_lux_latest - , listings_latest_src_28000.capacity AS listing__capacity_latest - , listings_latest_src_28000.listing_id AS listing - , 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_6 - ) subq_7 - WHERE subq_7.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' - ) subq_8 - ) subq_9 - ) subq_10 -) subq_11 + 1 AS listings + , listings_latest_src_28000.capacity AS largest_listing + , listings_latest_src_28000.capacity AS smallest_listing + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS created_at__extract_doy + , listings_latest_src_28000.country AS country_latest + , listings_latest_src_28000.is_lux AS is_lux_latest + , listings_latest_src_28000.capacity AS capacity_latest + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__ds__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__ds__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__ds__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__ds__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__ds__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__ds__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__ds__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__ds__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__ds__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__ds__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__ds__extract_doy + , DATE_TRUNC('day', listings_latest_src_28000.created_at) AS listing__created_at__day + , DATE_TRUNC('week', listings_latest_src_28000.created_at) AS listing__created_at__week + , DATE_TRUNC('month', listings_latest_src_28000.created_at) AS listing__created_at__month + , DATE_TRUNC('quarter', listings_latest_src_28000.created_at) AS listing__created_at__quarter + , DATE_TRUNC('year', listings_latest_src_28000.created_at) AS listing__created_at__year + , EXTRACT(year FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_year + , EXTRACT(quarter FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_quarter + , EXTRACT(month FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_month + , EXTRACT(day FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_day + , EXTRACT(isodow FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_dow + , EXTRACT(doy FROM listings_latest_src_28000.created_at) AS listing__created_at__extract_doy + , listings_latest_src_28000.country AS listing__country_latest + , listings_latest_src_28000.is_lux AS listing__is_lux_latest + , listings_latest_src_28000.capacity AS listing__capacity_latest + , listings_latest_src_28000.listing_id AS listing + , 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_5 + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-01' AND '2020-01-01' + ) subq_7 + ) subq_8 +) subq_9 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multiple_metrics_no_dimensions__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multiple_metrics_no_dimensions__plan0_optimized.sql index 18ff29de08..3a4b05c754 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multiple_metrics_no_dimensions__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_multiple_metrics_no_dimensions__plan0_optimized.sql @@ -1,7 +1,7 @@ -- Combine Aggregated Outputs SELECT - MAX(subq_17.bookings) AS bookings - , MAX(subq_23.listings) AS listings + MAX(subq_14.bookings) AS bookings + , MAX(subq_19.listings) AS listings FROM ( -- Read Elements From Semantic Model 'bookings_source' -- Metric Time Dimension 'ds' @@ -13,7 +13,7 @@ FROM ( SUM(1) AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 WHERE DATE_TRUNC('day', ds) BETWEEN '2020-01-01' AND '2020-01-01' -) subq_17 +) subq_14 CROSS JOIN ( -- Read Elements From Semantic Model 'listings_latest' -- Metric Time Dimension 'ds' @@ -25,4 +25,4 @@ CROSS JOIN ( SUM(1) AS listings FROM ***************************.dim_listings_latest listings_latest_src_28000 WHERE DATE_TRUNC('day', created_at) BETWEEN '2020-01-01' AND '2020-01-01' -) subq_23 +) subq_19 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0.sql index c4eac70b4c..968691e21d 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0.sql @@ -1,230 +1,129 @@ -- Compute Metrics via Expressions SELECT - subq_7.total_account_balance_first_day_of_month + subq_5.total_account_balance_first_day_of_month FROM ( -- Aggregate Measures SELECT - SUM(subq_6.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + SUM(subq_4.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month FROM ( + -- Join on MIN(ds_month) and [] grouping by None -- Pass Only Elements: ['total_account_balance_first_day_of_month',] SELECT - subq_5.total_account_balance_first_day_of_month + subq_1.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month FROM ( - -- Join on MIN(ds_month) and [] grouping by None + -- Metric Time Dimension 'ds_month' + -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] SELECT - subq_2.ds_month__month AS ds_month__month - , subq_2.total_account_balance_first_day_of_month AS total_account_balance_first_day_of_month + subq_0.ds_month__month + , subq_0.total_account_balance_first_day_of_month FROM ( + -- Read Elements From Semantic Model 'accounts_source' + SELECT + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 + ) subq_1 + INNER JOIN ( + -- Filter row on MIN(ds_month__month) + SELECT + MIN(subq_2.ds_month__month) AS ds_month__month__complete + FROM ( + -- Metric Time Dimension 'ds_month' -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] SELECT - subq_1.ds_month__month - , subq_1.total_account_balance_first_day_of_month + subq_0.ds_month__month + , subq_0.total_account_balance_first_day_of_month FROM ( - -- Metric Time Dimension 'ds_month' + -- Read Elements From Semantic Model 'accounts_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_month__month - , subq_0.ds_month__quarter - , subq_0.ds_month__year - , subq_0.ds_month__extract_year - , subq_0.ds_month__extract_quarter - , subq_0.ds_month__extract_month - , subq_0.account__ds__day - , subq_0.account__ds__week - , subq_0.account__ds__month - , subq_0.account__ds__quarter - , subq_0.account__ds__year - , subq_0.account__ds__extract_year - , subq_0.account__ds__extract_quarter - , subq_0.account__ds__extract_month - , subq_0.account__ds__extract_day - , subq_0.account__ds__extract_dow - , subq_0.account__ds__extract_doy - , subq_0.account__ds_month__month - , subq_0.account__ds_month__quarter - , subq_0.account__ds_month__year - , subq_0.account__ds_month__extract_year - , subq_0.account__ds_month__extract_quarter - , subq_0.account__ds_month__extract_month - , subq_0.ds_month__month AS metric_time__month - , subq_0.ds_month__quarter AS metric_time__quarter - , subq_0.ds_month__year AS metric_time__year - , subq_0.ds_month__extract_year AS metric_time__extract_year - , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter - , subq_0.ds_month__extract_month AS metric_time__extract_month - , subq_0.user - , subq_0.account__user - , subq_0.account_type - , subq_0.account__account_type - , subq_0.total_account_balance_first_day_of_month - FROM ( - -- Read Elements From Semantic Model 'accounts_source' - SELECT - accounts_source_src_28000.account_balance - , accounts_source_src_28000.account_balance AS total_account_balance_first_day - , accounts_source_src_28000.account_balance AS current_account_balance_by_user - , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month - , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month - , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter - , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year - , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year - , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter - , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month - , accounts_source_src_28000.account_type - , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day - , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week - , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month - , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter - , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year - , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year - , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter - , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month - , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day - , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow - , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy - , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month - , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter - , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year - , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year - , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter - , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month - , accounts_source_src_28000.account_type AS account__account_type - , accounts_source_src_28000.user_id AS user - , accounts_source_src_28000.user_id AS account__user - FROM ***************************.fct_accounts accounts_source_src_28000 - ) subq_0 - ) subq_1 + accounts_source_src_28000.account_balance + , accounts_source_src_28000.account_balance AS total_account_balance_first_day + , accounts_source_src_28000.account_balance AS current_account_balance_by_user + , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month + , accounts_source_src_28000.account_type + , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day + , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week + , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year + , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month + , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day + , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow + , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy + , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month + , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter + , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year + , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year + , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter + , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month + , accounts_source_src_28000.account_type AS account__account_type + , accounts_source_src_28000.user_id AS user + , accounts_source_src_28000.user_id AS account__user + FROM ***************************.fct_accounts accounts_source_src_28000 + ) subq_0 ) subq_2 - INNER JOIN ( - -- Filter row on MIN(ds_month__month) - SELECT - MIN(subq_3.ds_month__month) AS ds_month__month__complete - FROM ( - -- Pass Only Elements: ['total_account_balance_first_day_of_month', 'ds_month__month'] - SELECT - subq_1.ds_month__month - , subq_1.total_account_balance_first_day_of_month - FROM ( - -- Metric Time Dimension 'ds_month' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_month__month - , subq_0.ds_month__quarter - , subq_0.ds_month__year - , subq_0.ds_month__extract_year - , subq_0.ds_month__extract_quarter - , subq_0.ds_month__extract_month - , subq_0.account__ds__day - , subq_0.account__ds__week - , subq_0.account__ds__month - , subq_0.account__ds__quarter - , subq_0.account__ds__year - , subq_0.account__ds__extract_year - , subq_0.account__ds__extract_quarter - , subq_0.account__ds__extract_month - , subq_0.account__ds__extract_day - , subq_0.account__ds__extract_dow - , subq_0.account__ds__extract_doy - , subq_0.account__ds_month__month - , subq_0.account__ds_month__quarter - , subq_0.account__ds_month__year - , subq_0.account__ds_month__extract_year - , subq_0.account__ds_month__extract_quarter - , subq_0.account__ds_month__extract_month - , subq_0.ds_month__month AS metric_time__month - , subq_0.ds_month__quarter AS metric_time__quarter - , subq_0.ds_month__year AS metric_time__year - , subq_0.ds_month__extract_year AS metric_time__extract_year - , subq_0.ds_month__extract_quarter AS metric_time__extract_quarter - , subq_0.ds_month__extract_month AS metric_time__extract_month - , subq_0.user - , subq_0.account__user - , subq_0.account_type - , subq_0.account__account_type - , subq_0.total_account_balance_first_day_of_month - FROM ( - -- Read Elements From Semantic Model 'accounts_source' - SELECT - accounts_source_src_28000.account_balance - , accounts_source_src_28000.account_balance AS total_account_balance_first_day - , accounts_source_src_28000.account_balance AS current_account_balance_by_user - , accounts_source_src_28000.account_balance AS total_account_balance_first_day_of_month - , DATE_TRUNC('day', accounts_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', accounts_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', accounts_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', accounts_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM accounts_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM accounts_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM accounts_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM accounts_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS ds_month__month - , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS ds_month__quarter - , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS ds_month__year - , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS ds_month__extract_year - , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS ds_month__extract_quarter - , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS ds_month__extract_month - , accounts_source_src_28000.account_type - , DATE_TRUNC('day', accounts_source_src_28000.ds) AS account__ds__day - , DATE_TRUNC('week', accounts_source_src_28000.ds) AS account__ds__week - , DATE_TRUNC('month', accounts_source_src_28000.ds) AS account__ds__month - , DATE_TRUNC('quarter', accounts_source_src_28000.ds) AS account__ds__quarter - , DATE_TRUNC('year', accounts_source_src_28000.ds) AS account__ds__year - , EXTRACT(year FROM accounts_source_src_28000.ds) AS account__ds__extract_year - , EXTRACT(quarter FROM accounts_source_src_28000.ds) AS account__ds__extract_quarter - , EXTRACT(month FROM accounts_source_src_28000.ds) AS account__ds__extract_month - , EXTRACT(day FROM accounts_source_src_28000.ds) AS account__ds__extract_day - , EXTRACT(isodow FROM accounts_source_src_28000.ds) AS account__ds__extract_dow - , EXTRACT(doy FROM accounts_source_src_28000.ds) AS account__ds__extract_doy - , DATE_TRUNC('month', accounts_source_src_28000.ds_month) AS account__ds_month__month - , DATE_TRUNC('quarter', accounts_source_src_28000.ds_month) AS account__ds_month__quarter - , DATE_TRUNC('year', accounts_source_src_28000.ds_month) AS account__ds_month__year - , EXTRACT(year FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_year - , EXTRACT(quarter FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_quarter - , EXTRACT(month FROM accounts_source_src_28000.ds_month) AS account__ds_month__extract_month - , accounts_source_src_28000.account_type AS account__account_type - , accounts_source_src_28000.user_id AS user - , accounts_source_src_28000.user_id AS account__user - FROM ***************************.fct_accounts accounts_source_src_28000 - ) subq_0 - ) subq_1 - ) subq_3 - ) subq_4 - ON - subq_2.ds_month__month = subq_4.ds_month__month__complete - ) subq_5 - ) subq_6 -) subq_7 + ) subq_3 + ON + subq_1.ds_month__month = subq_3.ds_month__month__complete + ) subq_4 +) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql index 90b981493f..e82797d277 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_non_additive_dimension_with_non_default_grain__plan0_optimized.sql @@ -3,7 +3,7 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - SUM(subq_10.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month + SUM(subq_7.total_account_balance_first_day_of_month) AS total_account_balance_first_day_of_month FROM ( -- Read Elements From Semantic Model 'accounts_source' -- Metric Time Dimension 'ds_month' @@ -12,7 +12,7 @@ FROM ( DATE_TRUNC('month', ds_month) AS ds_month__month , account_balance AS total_account_balance_first_day_of_month FROM ***************************.fct_accounts accounts_source_src_28000 -) subq_10 +) subq_7 INNER JOIN ( -- Read Elements From Semantic Model 'accounts_source' -- Metric Time Dimension 'ds_month' @@ -21,6 +21,6 @@ INNER JOIN ( SELECT MIN(DATE_TRUNC('month', ds_month)) AS ds_month__month__complete FROM ***************************.fct_accounts accounts_source_src_28000 -) subq_12 +) subq_9 ON - subq_10.ds_month__month = subq_12.ds_month__month__complete + subq_7.ds_month__month = subq_9.ds_month__month__complete diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0.sql index 9331570241..e8bf5d4734 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0.sql @@ -1,544 +1,279 @@ -- Compute Metrics via Expressions SELECT - subq_8.user__home_state - , subq_8.identity_verifications + subq_5.user__home_state + , subq_5.identity_verifications FROM ( -- Aggregate Measures SELECT - subq_7.user__home_state - , SUM(subq_7.identity_verifications) AS identity_verifications + subq_4.user__home_state + , SUM(subq_4.identity_verifications) AS identity_verifications FROM ( + -- Join Standard Outputs -- Pass Only Elements: ['identity_verifications', 'user__home_state'] SELECT - subq_6.user__home_state - , subq_6.identity_verifications + subq_1.identity_verifications AS identity_verifications FROM ( - -- Join Standard Outputs + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['identity_verifications', 'ds_partitioned__day', 'user'] SELECT - subq_2.ds_partitioned__day AS ds_partitioned__day - , subq_5.ds_partitioned__day AS user__ds_partitioned__day - , subq_2.user AS user - , subq_5.home_state AS user__home_state - , subq_2.identity_verifications AS identity_verifications + subq_0.ds_partitioned__day + , subq_0.user + , subq_0.identity_verifications FROM ( - -- Pass Only Elements: ['identity_verifications', 'ds_partitioned__day', 'user'] + -- Read Elements From Semantic Model 'id_verifications' SELECT - subq_1.ds_partitioned__day - , subq_1.user - , subq_1.identity_verifications - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.verification__ds__day - , subq_0.verification__ds__week - , subq_0.verification__ds__month - , subq_0.verification__ds__quarter - , subq_0.verification__ds__year - , subq_0.verification__ds__extract_year - , subq_0.verification__ds__extract_quarter - , subq_0.verification__ds__extract_month - , subq_0.verification__ds__extract_day - , subq_0.verification__ds__extract_dow - , subq_0.verification__ds__extract_doy - , subq_0.verification__ds_partitioned__day - , subq_0.verification__ds_partitioned__week - , subq_0.verification__ds_partitioned__month - , subq_0.verification__ds_partitioned__quarter - , subq_0.verification__ds_partitioned__year - , subq_0.verification__ds_partitioned__extract_year - , subq_0.verification__ds_partitioned__extract_quarter - , subq_0.verification__ds_partitioned__extract_month - , subq_0.verification__ds_partitioned__extract_day - , subq_0.verification__ds_partitioned__extract_dow - , subq_0.verification__ds_partitioned__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.verification - , subq_0.user - , subq_0.verification__user - , subq_0.verification_type - , subq_0.verification__verification_type - , subq_0.identity_verifications - FROM ( - -- Read Elements From Semantic Model 'id_verifications' - SELECT - 1 AS identity_verifications - , DATE_TRUNC('day', id_verifications_src_28000.ds) AS ds__day - , DATE_TRUNC('week', id_verifications_src_28000.ds) AS ds__week - , DATE_TRUNC('month', id_verifications_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', id_verifications_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', id_verifications_src_28000.ds) AS ds__year - , EXTRACT(year FROM id_verifications_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM id_verifications_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM id_verifications_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM id_verifications_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM id_verifications_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM id_verifications_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , id_verifications_src_28000.verification_type - , DATE_TRUNC('day', id_verifications_src_28000.ds) AS verification__ds__day - , DATE_TRUNC('week', id_verifications_src_28000.ds) AS verification__ds__week - , DATE_TRUNC('month', id_verifications_src_28000.ds) AS verification__ds__month - , DATE_TRUNC('quarter', id_verifications_src_28000.ds) AS verification__ds__quarter - , DATE_TRUNC('year', id_verifications_src_28000.ds) AS verification__ds__year - , EXTRACT(year FROM id_verifications_src_28000.ds) AS verification__ds__extract_year - , EXTRACT(quarter FROM id_verifications_src_28000.ds) AS verification__ds__extract_quarter - , EXTRACT(month FROM id_verifications_src_28000.ds) AS verification__ds__extract_month - , EXTRACT(day FROM id_verifications_src_28000.ds) AS verification__ds__extract_day - , EXTRACT(isodow FROM id_verifications_src_28000.ds) AS verification__ds__extract_dow - , EXTRACT(doy FROM id_verifications_src_28000.ds) AS verification__ds__extract_doy - , DATE_TRUNC('day', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__day - , DATE_TRUNC('week', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__week - , DATE_TRUNC('month', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__month - , DATE_TRUNC('quarter', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__quarter - , DATE_TRUNC('year', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__year - , EXTRACT(year FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_year - , EXTRACT(quarter FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_quarter - , EXTRACT(month FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_month - , EXTRACT(day FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_day - , EXTRACT(isodow FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_dow - , EXTRACT(doy FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_doy - , id_verifications_src_28000.verification_type AS verification__verification_type - , id_verifications_src_28000.verification_id AS verification - , id_verifications_src_28000.user_id AS user - , id_verifications_src_28000.user_id AS verification__user - FROM ***************************.fct_id_verifications id_verifications_src_28000 - ) subq_0 - ) subq_1 - ) subq_2 - LEFT OUTER JOIN ( - -- Pass Only Elements: ['home_state', 'ds_partitioned__day', 'user'] + 1 AS identity_verifications + , DATE_TRUNC('day', id_verifications_src_28000.ds) AS ds__day + , DATE_TRUNC('week', id_verifications_src_28000.ds) AS ds__week + , DATE_TRUNC('month', id_verifications_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', id_verifications_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', id_verifications_src_28000.ds) AS ds__year + , EXTRACT(year FROM id_verifications_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM id_verifications_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM id_verifications_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , id_verifications_src_28000.verification_type + , DATE_TRUNC('day', id_verifications_src_28000.ds) AS verification__ds__day + , DATE_TRUNC('week', id_verifications_src_28000.ds) AS verification__ds__week + , DATE_TRUNC('month', id_verifications_src_28000.ds) AS verification__ds__month + , DATE_TRUNC('quarter', id_verifications_src_28000.ds) AS verification__ds__quarter + , DATE_TRUNC('year', id_verifications_src_28000.ds) AS verification__ds__year + , EXTRACT(year FROM id_verifications_src_28000.ds) AS verification__ds__extract_year + , EXTRACT(quarter FROM id_verifications_src_28000.ds) AS verification__ds__extract_quarter + , EXTRACT(month FROM id_verifications_src_28000.ds) AS verification__ds__extract_month + , EXTRACT(day FROM id_verifications_src_28000.ds) AS verification__ds__extract_day + , EXTRACT(isodow FROM id_verifications_src_28000.ds) AS verification__ds__extract_dow + , EXTRACT(doy FROM id_verifications_src_28000.ds) AS verification__ds__extract_doy + , DATE_TRUNC('day', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__day + , DATE_TRUNC('week', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__week + , DATE_TRUNC('month', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__month + , DATE_TRUNC('quarter', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__quarter + , DATE_TRUNC('year', id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__year + , EXTRACT(year FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_year + , EXTRACT(quarter FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_quarter + , EXTRACT(month FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_month + , EXTRACT(day FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_day + , EXTRACT(isodow FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_dow + , EXTRACT(doy FROM id_verifications_src_28000.ds_partitioned) AS verification__ds_partitioned__extract_doy + , id_verifications_src_28000.verification_type AS verification__verification_type + , id_verifications_src_28000.verification_id AS verification + , id_verifications_src_28000.user_id AS user + , id_verifications_src_28000.user_id AS verification__user + FROM ***************************.fct_id_verifications id_verifications_src_28000 + ) subq_0 + ) subq_1 + LEFT OUTER JOIN ( + -- Metric Time Dimension 'created_at' + -- Pass Only Elements: ['home_state', 'ds_partitioned__day', 'user'] + SELECT + subq_2.ds_partitioned__day + , subq_2.user + , subq_2.home_state + FROM ( + -- Read Elements From Semantic Model 'users_ds_source' SELECT - subq_4.ds_partitioned__day - , subq_4.user - , subq_4.home_state - FROM ( - -- Metric Time Dimension 'created_at' - SELECT - subq_3.ds__day - , subq_3.ds__week - , subq_3.ds__month - , subq_3.ds__quarter - , subq_3.ds__year - , subq_3.ds__extract_year - , subq_3.ds__extract_quarter - , subq_3.ds__extract_month - , subq_3.ds__extract_day - , subq_3.ds__extract_dow - , subq_3.ds__extract_doy - , subq_3.created_at__day - , subq_3.created_at__week - , subq_3.created_at__month - , subq_3.created_at__quarter - , subq_3.created_at__year - , subq_3.created_at__extract_year - , subq_3.created_at__extract_quarter - , subq_3.created_at__extract_month - , subq_3.created_at__extract_day - , subq_3.created_at__extract_dow - , subq_3.created_at__extract_doy - , subq_3.ds_partitioned__day - , subq_3.ds_partitioned__week - , subq_3.ds_partitioned__month - , subq_3.ds_partitioned__quarter - , subq_3.ds_partitioned__year - , subq_3.ds_partitioned__extract_year - , subq_3.ds_partitioned__extract_quarter - , subq_3.ds_partitioned__extract_month - , subq_3.ds_partitioned__extract_day - , subq_3.ds_partitioned__extract_dow - , subq_3.ds_partitioned__extract_doy - , subq_3.last_profile_edit_ts__millisecond - , subq_3.last_profile_edit_ts__second - , subq_3.last_profile_edit_ts__minute - , subq_3.last_profile_edit_ts__hour - , subq_3.last_profile_edit_ts__day - , subq_3.last_profile_edit_ts__week - , subq_3.last_profile_edit_ts__month - , subq_3.last_profile_edit_ts__quarter - , subq_3.last_profile_edit_ts__year - , subq_3.last_profile_edit_ts__extract_year - , subq_3.last_profile_edit_ts__extract_quarter - , subq_3.last_profile_edit_ts__extract_month - , subq_3.last_profile_edit_ts__extract_day - , subq_3.last_profile_edit_ts__extract_dow - , subq_3.last_profile_edit_ts__extract_doy - , subq_3.bio_added_ts__second - , subq_3.bio_added_ts__minute - , subq_3.bio_added_ts__hour - , subq_3.bio_added_ts__day - , subq_3.bio_added_ts__week - , subq_3.bio_added_ts__month - , subq_3.bio_added_ts__quarter - , subq_3.bio_added_ts__year - , subq_3.bio_added_ts__extract_year - , subq_3.bio_added_ts__extract_quarter - , subq_3.bio_added_ts__extract_month - , subq_3.bio_added_ts__extract_day - , subq_3.bio_added_ts__extract_dow - , subq_3.bio_added_ts__extract_doy - , subq_3.last_login_ts__minute - , subq_3.last_login_ts__hour - , subq_3.last_login_ts__day - , subq_3.last_login_ts__week - , subq_3.last_login_ts__month - , subq_3.last_login_ts__quarter - , subq_3.last_login_ts__year - , subq_3.last_login_ts__extract_year - , subq_3.last_login_ts__extract_quarter - , subq_3.last_login_ts__extract_month - , subq_3.last_login_ts__extract_day - , subq_3.last_login_ts__extract_dow - , subq_3.last_login_ts__extract_doy - , subq_3.archived_at__hour - , subq_3.archived_at__day - , subq_3.archived_at__week - , subq_3.archived_at__month - , subq_3.archived_at__quarter - , subq_3.archived_at__year - , subq_3.archived_at__extract_year - , subq_3.archived_at__extract_quarter - , subq_3.archived_at__extract_month - , subq_3.archived_at__extract_day - , subq_3.archived_at__extract_dow - , subq_3.archived_at__extract_doy - , subq_3.user__ds__day - , subq_3.user__ds__week - , subq_3.user__ds__month - , subq_3.user__ds__quarter - , subq_3.user__ds__year - , subq_3.user__ds__extract_year - , subq_3.user__ds__extract_quarter - , subq_3.user__ds__extract_month - , subq_3.user__ds__extract_day - , subq_3.user__ds__extract_dow - , subq_3.user__ds__extract_doy - , subq_3.user__created_at__day - , subq_3.user__created_at__week - , subq_3.user__created_at__month - , subq_3.user__created_at__quarter - , subq_3.user__created_at__year - , subq_3.user__created_at__extract_year - , subq_3.user__created_at__extract_quarter - , subq_3.user__created_at__extract_month - , subq_3.user__created_at__extract_day - , subq_3.user__created_at__extract_dow - , subq_3.user__created_at__extract_doy - , subq_3.user__ds_partitioned__day - , subq_3.user__ds_partitioned__week - , subq_3.user__ds_partitioned__month - , subq_3.user__ds_partitioned__quarter - , subq_3.user__ds_partitioned__year - , subq_3.user__ds_partitioned__extract_year - , subq_3.user__ds_partitioned__extract_quarter - , subq_3.user__ds_partitioned__extract_month - , subq_3.user__ds_partitioned__extract_day - , subq_3.user__ds_partitioned__extract_dow - , subq_3.user__ds_partitioned__extract_doy - , subq_3.user__last_profile_edit_ts__millisecond - , subq_3.user__last_profile_edit_ts__second - , subq_3.user__last_profile_edit_ts__minute - , subq_3.user__last_profile_edit_ts__hour - , subq_3.user__last_profile_edit_ts__day - , subq_3.user__last_profile_edit_ts__week - , subq_3.user__last_profile_edit_ts__month - , subq_3.user__last_profile_edit_ts__quarter - , subq_3.user__last_profile_edit_ts__year - , subq_3.user__last_profile_edit_ts__extract_year - , subq_3.user__last_profile_edit_ts__extract_quarter - , subq_3.user__last_profile_edit_ts__extract_month - , subq_3.user__last_profile_edit_ts__extract_day - , subq_3.user__last_profile_edit_ts__extract_dow - , subq_3.user__last_profile_edit_ts__extract_doy - , subq_3.user__bio_added_ts__second - , subq_3.user__bio_added_ts__minute - , subq_3.user__bio_added_ts__hour - , subq_3.user__bio_added_ts__day - , subq_3.user__bio_added_ts__week - , subq_3.user__bio_added_ts__month - , subq_3.user__bio_added_ts__quarter - , subq_3.user__bio_added_ts__year - , subq_3.user__bio_added_ts__extract_year - , subq_3.user__bio_added_ts__extract_quarter - , subq_3.user__bio_added_ts__extract_month - , subq_3.user__bio_added_ts__extract_day - , subq_3.user__bio_added_ts__extract_dow - , subq_3.user__bio_added_ts__extract_doy - , subq_3.user__last_login_ts__minute - , subq_3.user__last_login_ts__hour - , subq_3.user__last_login_ts__day - , subq_3.user__last_login_ts__week - , subq_3.user__last_login_ts__month - , subq_3.user__last_login_ts__quarter - , subq_3.user__last_login_ts__year - , subq_3.user__last_login_ts__extract_year - , subq_3.user__last_login_ts__extract_quarter - , subq_3.user__last_login_ts__extract_month - , subq_3.user__last_login_ts__extract_day - , subq_3.user__last_login_ts__extract_dow - , subq_3.user__last_login_ts__extract_doy - , subq_3.user__archived_at__hour - , subq_3.user__archived_at__day - , subq_3.user__archived_at__week - , subq_3.user__archived_at__month - , subq_3.user__archived_at__quarter - , subq_3.user__archived_at__year - , subq_3.user__archived_at__extract_year - , subq_3.user__archived_at__extract_quarter - , subq_3.user__archived_at__extract_month - , subq_3.user__archived_at__extract_day - , subq_3.user__archived_at__extract_dow - , subq_3.user__archived_at__extract_doy - , subq_3.created_at__day AS metric_time__day - , subq_3.created_at__week AS metric_time__week - , subq_3.created_at__month AS metric_time__month - , subq_3.created_at__quarter AS metric_time__quarter - , subq_3.created_at__year AS metric_time__year - , subq_3.created_at__extract_year AS metric_time__extract_year - , subq_3.created_at__extract_quarter AS metric_time__extract_quarter - , subq_3.created_at__extract_month AS metric_time__extract_month - , subq_3.created_at__extract_day AS metric_time__extract_day - , subq_3.created_at__extract_dow AS metric_time__extract_dow - , subq_3.created_at__extract_doy AS metric_time__extract_doy - , subq_3.user - , subq_3.home_state - , subq_3.user__home_state - , subq_3.new_users - FROM ( - -- Read Elements From Semantic Model 'users_ds_source' - SELECT - 1 AS new_users - , 1 AS archived_users - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year - , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year - , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy - , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day - , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week - , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year - , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy - , users_ds_source_src_28000.home_state AS user__home_state - , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond - , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy - , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second - , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy - , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute - , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour - , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day - , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week - , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year - , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy - , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour - , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day - , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week - , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month - , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter - , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year - , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year - , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter - , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month - , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day - , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow - , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy - , users_ds_source_src_28000.user_id AS user - FROM ***************************.dim_users users_ds_source_src_28000 - ) subq_3 - ) subq_4 - ) subq_5 - ON - ( - subq_2.user = subq_5.user - ) AND ( - subq_2.ds_partitioned__day = subq_5.ds_partitioned__day - ) - ) subq_6 - ) subq_7 + 1 AS new_users + , 1 AS archived_users + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS archived_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds) AS user__ds__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds) AS user__ds__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds) AS user__ds__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds) AS user__ds__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds) AS user__ds__year + , EXTRACT(year FROM users_ds_source_src_28000.ds) AS user__ds__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds) AS user__ds__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds) AS user__ds__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds) AS user__ds__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds) AS user__ds__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds) AS user__ds__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.created_at) AS user__created_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.created_at) AS user__created_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.created_at) AS user__created_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.created_at) AS user__created_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.created_at) AS user__created_at__year + , EXTRACT(year FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.created_at) AS user__created_at__extract_doy + , DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__day + , DATE_TRUNC('week', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__week + , DATE_TRUNC('month', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__year + , EXTRACT(year FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.ds_partitioned) AS user__ds_partitioned__extract_doy + , users_ds_source_src_28000.home_state AS user__home_state + , DATE_TRUNC('millisecond', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__millisecond + , DATE_TRUNC('second', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_profile_edit_ts) AS user__last_profile_edit_ts__extract_doy + , DATE_TRUNC('second', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__second + , DATE_TRUNC('minute', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.bio_added_ts) AS user__bio_added_ts__extract_doy + , DATE_TRUNC('minute', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__minute + , DATE_TRUNC('hour', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__hour + , DATE_TRUNC('day', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__day + , DATE_TRUNC('week', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__week + , DATE_TRUNC('month', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__year + , EXTRACT(year FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.last_login_ts) AS user__last_login_ts__extract_doy + , DATE_TRUNC('hour', users_ds_source_src_28000.archived_at) AS user__archived_at__hour + , DATE_TRUNC('day', users_ds_source_src_28000.archived_at) AS user__archived_at__day + , DATE_TRUNC('week', users_ds_source_src_28000.archived_at) AS user__archived_at__week + , DATE_TRUNC('month', users_ds_source_src_28000.archived_at) AS user__archived_at__month + , DATE_TRUNC('quarter', users_ds_source_src_28000.archived_at) AS user__archived_at__quarter + , DATE_TRUNC('year', users_ds_source_src_28000.archived_at) AS user__archived_at__year + , EXTRACT(year FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_year + , EXTRACT(quarter FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_quarter + , EXTRACT(month FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_month + , EXTRACT(day FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_day + , EXTRACT(isodow FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_dow + , EXTRACT(doy FROM users_ds_source_src_28000.archived_at) AS user__archived_at__extract_doy + , users_ds_source_src_28000.user_id AS user + FROM ***************************.dim_users users_ds_source_src_28000 + ) subq_2 + ) subq_3 + ON + ( + subq_1.user = subq_3.user + ) AND ( + subq_1.ds_partitioned__day = subq_3.ds_partitioned__day + ) + ) subq_4 GROUP BY - subq_7.user__home_state -) subq_8 + subq_4.user__home_state +) subq_5 diff --git a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0_optimized.sql b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0_optimized.sql index be2da473cc..9a2e746ea9 100644 --- a/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0_optimized.sql +++ b/tests_metricflow/snapshots/test_query_rendering.py/SqlQueryPlan/DuckDB/test_partitioned_join__plan0_optimized.sql @@ -3,8 +3,8 @@ -- Aggregate Measures -- Compute Metrics via Expressions SELECT - users_ds_source_src_28000.home_state AS user__home_state - , SUM(subq_11.identity_verifications) AS identity_verifications + subq_10.user__home_state AS user__home_state + , SUM(subq_7.identity_verifications) AS identity_verifications FROM ( -- Read Elements From Semantic Model 'id_verifications' -- Metric Time Dimension 'ds' @@ -14,14 +14,14 @@ FROM ( , user_id AS user , 1 AS identity_verifications FROM ***************************.fct_id_verifications id_verifications_src_28000 -) subq_11 +) subq_7 LEFT OUTER JOIN ***************************.dim_users users_ds_source_src_28000 ON ( - subq_11.user = users_ds_source_src_28000.user_id + subq_7.user = users_ds_source_src_28000.user_id ) AND ( - subq_11.ds_partitioned__day = DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) + subq_7.ds_partitioned__day = DATE_TRUNC('day', users_ds_source_src_28000.ds_partitioned) ) GROUP BY - users_ds_source_src_28000.home_state + subq_10.user__home_state diff --git a/tests_metricflow/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration__query.sql b/tests_metricflow/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration__query.sql index afe59d05cf..4af155e00a 100644 --- a/tests_metricflow/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration__query.sql +++ b/tests_metricflow/snapshots/test_rendered_query.py/str/DuckDB/test_id_enumeration__query.sql @@ -1,8 +1,8 @@ -- Combine Aggregated Outputs SELECT - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) AS metric_time__day - , MAX(subq_4.bookings) AS bookings - , MAX(subq_9.listings) AS listings + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) AS metric_time__day + , MAX(subq_3.bookings) AS bookings + , MAX(subq_7.listings) AS listings FROM ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -17,10 +17,10 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_10000 - ) subq_2 + ) subq_1 GROUP BY metric_time__day -) subq_4 +) subq_3 FULL OUTER JOIN ( -- Aggregate Measures -- Compute Metrics via Expressions @@ -35,11 +35,11 @@ FULL OUTER JOIN ( DATE_TRUNC('day', created_at) AS metric_time__day , 1 AS listings FROM ***************************.dim_listings_latest listings_latest_src_10000 - ) subq_7 + ) subq_5 GROUP BY metric_time__day -) subq_9 +) subq_7 ON - subq_4.metric_time__day = subq_9.metric_time__day + subq_3.metric_time__day = subq_7.metric_time__day GROUP BY - COALESCE(subq_4.metric_time__day, subq_9.metric_time__day) + COALESCE(subq_3.metric_time__day, subq_7.metric_time__day) diff --git a/tests_metricflow/snapshots/test_rendered_query.py/str/DuckDB/test_render_query__query0.sql b/tests_metricflow/snapshots/test_rendered_query.py/str/DuckDB/test_render_query__query0.sql index 5cf9ed8596..15fc7a48df 100644 --- a/tests_metricflow/snapshots/test_rendered_query.py/str/DuckDB/test_render_query__query0.sql +++ b/tests_metricflow/snapshots/test_rendered_query.py/str/DuckDB/test_render_query__query0.sql @@ -11,6 +11,6 @@ FROM ( DATE_TRUNC('day', ds) AS metric_time__day , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_10000 -) subq_2 +) subq_1 GROUP BY 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 a7fd42dafc..edd20e028a 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 @@ -1,338 +1,237 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.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 ( -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] SELECT - subq_7.metric_time__day - , subq_7.bookings + subq_6.metric_time__day + , subq_6.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.bookings AS bookings + subq_4.metric_time__day AS metric_time__day + , subq_3.bookings AS bookings FROM ( -- Time Spine 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_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + WHERE subq_5.ds BETWEEN '2020-01-03' AND '2020-01-05' + ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , SUM(subq_3.bookings) AS bookings + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings FROM ( + -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_2.metric_time__day - , subq_2.bookings + subq_1.metric_time__day + , subq_1.bookings FROM ( - -- Constrain Time Range to [2020-01-03T00:00:00, 2020-01-05T00:00:00] + -- Metric Time Dimension 'ds' SELECT - subq_1.ds__day - , subq_1.ds__week - , subq_1.ds__month - , subq_1.ds__quarter - , subq_1.ds__year - , subq_1.ds__extract_year - , subq_1.ds__extract_quarter - , subq_1.ds__extract_month - , subq_1.ds__extract_day - , subq_1.ds__extract_dow - , subq_1.ds__extract_doy - , subq_1.ds_partitioned__day - , subq_1.ds_partitioned__week - , subq_1.ds_partitioned__month - , subq_1.ds_partitioned__quarter - , subq_1.ds_partitioned__year - , subq_1.ds_partitioned__extract_year - , subq_1.ds_partitioned__extract_quarter - , subq_1.ds_partitioned__extract_month - , subq_1.ds_partitioned__extract_day - , subq_1.ds_partitioned__extract_dow - , subq_1.ds_partitioned__extract_doy - , subq_1.paid_at__day - , subq_1.paid_at__week - , subq_1.paid_at__month - , subq_1.paid_at__quarter - , subq_1.paid_at__year - , subq_1.paid_at__extract_year - , subq_1.paid_at__extract_quarter - , subq_1.paid_at__extract_month - , subq_1.paid_at__extract_day - , subq_1.paid_at__extract_dow - , subq_1.paid_at__extract_doy - , subq_1.booking__ds__day - , subq_1.booking__ds__week - , subq_1.booking__ds__month - , subq_1.booking__ds__quarter - , subq_1.booking__ds__year - , subq_1.booking__ds__extract_year - , subq_1.booking__ds__extract_quarter - , subq_1.booking__ds__extract_month - , subq_1.booking__ds__extract_day - , subq_1.booking__ds__extract_dow - , subq_1.booking__ds__extract_doy - , subq_1.booking__ds_partitioned__day - , subq_1.booking__ds_partitioned__week - , subq_1.booking__ds_partitioned__month - , subq_1.booking__ds_partitioned__quarter - , subq_1.booking__ds_partitioned__year - , subq_1.booking__ds_partitioned__extract_year - , subq_1.booking__ds_partitioned__extract_quarter - , subq_1.booking__ds_partitioned__extract_month - , subq_1.booking__ds_partitioned__extract_day - , subq_1.booking__ds_partitioned__extract_dow - , subq_1.booking__ds_partitioned__extract_doy - , subq_1.booking__paid_at__day - , subq_1.booking__paid_at__week - , subq_1.booking__paid_at__month - , subq_1.booking__paid_at__quarter - , subq_1.booking__paid_at__year - , subq_1.booking__paid_at__extract_year - , subq_1.booking__paid_at__extract_quarter - , subq_1.booking__paid_at__extract_month - , subq_1.booking__paid_at__extract_day - , subq_1.booking__paid_at__extract_dow - , subq_1.booking__paid_at__extract_doy - , subq_1.metric_time__day - , subq_1.metric_time__week - , subq_1.metric_time__month - , subq_1.metric_time__quarter - , subq_1.metric_time__year - , subq_1.metric_time__extract_year - , subq_1.metric_time__extract_quarter - , subq_1.metric_time__extract_month - , subq_1.metric_time__extract_day - , subq_1.metric_time__extract_dow - , subq_1.metric_time__extract_doy - , subq_1.listing - , subq_1.guest - , subq_1.host - , subq_1.booking__listing - , subq_1.booking__guest - , subq_1.booking__host - , subq_1.is_instant - , subq_1.booking__is_instant - , subq_1.bookings - , subq_1.instant_bookings - , subq_1.booking_value - , subq_1.max_booking_value - , subq_1.min_booking_value - , subq_1.bookers - , subq_1.average_booking_value - , subq_1.referred_bookings - , subq_1.median_booking_value - , subq_1.booking_value_p99 - , subq_1.discrete_booking_value_p99 - , subq_1.approximate_continuous_booking_value_p99 - , subq_1.approximate_discrete_booking_value_p99 + subq_0.ds__day + , subq_0.ds__week + , subq_0.ds__month + , subq_0.ds__quarter + , subq_0.ds__year + , subq_0.ds__extract_year + , subq_0.ds__extract_quarter + , subq_0.ds__extract_month + , subq_0.ds__extract_day + , subq_0.ds__extract_dow + , subq_0.ds__extract_doy + , subq_0.ds_partitioned__day + , subq_0.ds_partitioned__week + , subq_0.ds_partitioned__month + , subq_0.ds_partitioned__quarter + , subq_0.ds_partitioned__year + , subq_0.ds_partitioned__extract_year + , subq_0.ds_partitioned__extract_quarter + , subq_0.ds_partitioned__extract_month + , subq_0.ds_partitioned__extract_day + , subq_0.ds_partitioned__extract_dow + , subq_0.ds_partitioned__extract_doy + , subq_0.paid_at__day + , subq_0.paid_at__week + , subq_0.paid_at__month + , subq_0.paid_at__quarter + , subq_0.paid_at__year + , subq_0.paid_at__extract_year + , subq_0.paid_at__extract_quarter + , subq_0.paid_at__extract_month + , subq_0.paid_at__extract_day + , subq_0.paid_at__extract_dow + , subq_0.paid_at__extract_doy + , subq_0.booking__ds__day + , subq_0.booking__ds__week + , subq_0.booking__ds__month + , subq_0.booking__ds__quarter + , subq_0.booking__ds__year + , subq_0.booking__ds__extract_year + , subq_0.booking__ds__extract_quarter + , subq_0.booking__ds__extract_month + , subq_0.booking__ds__extract_day + , subq_0.booking__ds__extract_dow + , subq_0.booking__ds__extract_doy + , subq_0.booking__ds_partitioned__day + , subq_0.booking__ds_partitioned__week + , subq_0.booking__ds_partitioned__month + , subq_0.booking__ds_partitioned__quarter + , subq_0.booking__ds_partitioned__year + , subq_0.booking__ds_partitioned__extract_year + , subq_0.booking__ds_partitioned__extract_quarter + , subq_0.booking__ds_partitioned__extract_month + , subq_0.booking__ds_partitioned__extract_day + , subq_0.booking__ds_partitioned__extract_dow + , subq_0.booking__ds_partitioned__extract_doy + , subq_0.booking__paid_at__day + , subq_0.booking__paid_at__week + , subq_0.booking__paid_at__month + , subq_0.booking__paid_at__quarter + , subq_0.booking__paid_at__year + , subq_0.booking__paid_at__extract_year + , subq_0.booking__paid_at__extract_quarter + , subq_0.booking__paid_at__extract_month + , subq_0.booking__paid_at__extract_day + , subq_0.booking__paid_at__extract_dow + , subq_0.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 + , subq_0.guest + , subq_0.host + , subq_0.booking__listing + , subq_0.booking__guest + , subq_0.booking__host + , subq_0.is_instant + , subq_0.booking__is_instant + , subq_0.bookings + , subq_0.instant_bookings + , subq_0.booking_value + , subq_0.max_booking_value + , subq_0.min_booking_value + , subq_0.bookers + , subq_0.average_booking_value + , subq_0.referred_bookings + , subq_0.median_booking_value + , subq_0.booking_value_p99 + , subq_0.discrete_booking_value_p99 + , subq_0.approximate_continuous_booking_value_p99 + , subq_0.approximate_discrete_booking_value_p99 FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - WHERE subq_1.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_2 - ) subq_3 + 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 + ) subq_1 + WHERE subq_1.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' + ) subq_2 GROUP BY - subq_3.metric_time__day - ) subq_4 + subq_2.metric_time__day + ) subq_3 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_4.metric_time__day = subq_3.metric_time__day + ) subq_6 + WHERE subq_6.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_7 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 fb7e2c593f..619f6620dd 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 @@ -6,15 +6,15 @@ 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_12.metric_time__day AS metric_time__day + , subq_11.bookings AS bookings FROM ( -- Time Spine SELECT ds AS metric_time__day - FROM ***************************.mf_time_spine subq_15 + FROM ***************************.mf_time_spine subq_13 WHERE ds BETWEEN '2020-01-03' AND '2020-01-05' - ) subq_14 + ) subq_12 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -30,11 +30,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_10 GROUP BY metric_time__day - ) subq_13 + ) subq_11 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_12.metric_time__day = subq_11.metric_time__day + WHERE subq_12.metric_time__day BETWEEN '2020-01-03' AND '2020-01-05' +) subq_15 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 0ea077947e..1c545d8e80 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 @@ -1,227 +1,126 @@ -- Compute Metrics via Expressions SELECT - subq_6.metric_time__day - , subq_6.bookings AS bookings_join_to_time_spine + subq_5.metric_time__day + , subq_5.bookings AS bookings_join_to_time_spine FROM ( -- Join to Time Spine Dataset SELECT - subq_4.metric_time__day AS metric_time__day - , subq_3.bookings AS bookings + subq_3.metric_time__day AS metric_time__day + , subq_2.bookings AS bookings FROM ( -- Time Spine SELECT - subq_5.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_5 - ) subq_4 + subq_4.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_4 + ) subq_3 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_2.metric_time__day - , SUM(subq_2.bookings) AS bookings + subq_1.metric_time__day + , SUM(subq_1.bookings) AS bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 GROUP BY - subq_2.metric_time__day - ) subq_3 + subq_1.metric_time__day + ) subq_2 ON - subq_4.metric_time__day = subq_3.metric_time__day -) subq_6 + subq_3.metric_time__day = subq_2.metric_time__day +) subq_5 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 03e7c6a8a1..1326ac7b81 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 @@ -1,9 +1,9 @@ -- 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 + subq_10.ds AS metric_time__day + , subq_8.bookings AS bookings_join_to_time_spine +FROM ***************************.mf_time_spine subq_10 LEFT OUTER JOIN ( -- Aggregate Measures SELECT @@ -17,9 +17,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_7 GROUP BY metric_time__day -) subq_10 +) subq_8 ON - subq_12.ds = subq_10.metric_time__day + subq_10.ds = subq_8.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 a39da38b06..52c89a8793 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 @@ -1,242 +1,135 @@ -- Compute Metrics via Expressions SELECT - subq_8.metric_time__day - , COALESCE(subq_8.bookings, 0) AS bookings_fill_nulls_with_0 + subq_6.metric_time__day + , COALESCE(subq_6.bookings, 0) AS bookings_fill_nulls_with_0 FROM ( -- Join to Time Spine Dataset SELECT - subq_6.metric_time__day AS metric_time__day - , subq_5.bookings AS bookings + subq_4.metric_time__day AS metric_time__day + , subq_3.bookings AS bookings FROM ( -- Time Spine SELECT - subq_7.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_7 - ) subq_6 + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_4.metric_time__day - , SUM(subq_4.bookings) AS bookings + subq_2.metric_time__day + , SUM(subq_2.bookings) AS bookings FROM ( + -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] SELECT - subq_3.metric_time__day - , subq_3.bookings + subq_1.metric_time__day + , subq_1.bookings FROM ( - -- Constrain Output with WHERE + -- Metric Time Dimension 'ds' + -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_0.ds__day AS metric_time__day + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings - FROM ( - -- Metric Time Dimension 'ds' - SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 - WHERE booking__is_instant - ) subq_3 - ) subq_4 + 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 + ) subq_1 + WHERE booking__is_instant + ) subq_2 GROUP BY - subq_4.metric_time__day - ) subq_5 + subq_2.metric_time__day + ) subq_3 ON - subq_6.metric_time__day = subq_5.metric_time__day -) subq_8 + subq_4.metric_time__day = subq_3.metric_time__day +) subq_6 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 1185bf668d..c7a906ffed 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 @@ -5,9 +5,9 @@ SELECT FROM ( -- Join to Time Spine Dataset SELECT - subq_16.ds AS metric_time__day - , subq_14.bookings AS bookings - FROM ***************************.mf_time_spine subq_16 + subq_12.ds AS metric_time__day + , subq_10.bookings AS bookings + FROM ***************************.mf_time_spine subq_12 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Pass Only Elements: ['bookings', 'metric_time__day'] @@ -24,11 +24,11 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_8 WHERE booking__is_instant GROUP BY metric_time__day - ) subq_14 + ) subq_10 ON - subq_16.ds = subq_14.metric_time__day -) subq_17 + subq_12.ds = subq_10.metric_time__day +) subq_13 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 ed0bc69197..c8a07f5b47 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 @@ -1,248 +1,147 @@ -- 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_7.metric_time__day + , subq_7.booking__is_instant + , COALESCE(subq_7.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_6.metric_time__day + , subq_6.booking__is_instant + , subq_6.bookings FROM ( -- Join to Time Spine Dataset SELECT - subq_5.metric_time__day AS metric_time__day - , subq_4.booking__is_instant AS booking__is_instant - , subq_4.bookings AS bookings + subq_4.metric_time__day AS metric_time__day + , subq_3.booking__is_instant AS booking__is_instant + , subq_3.bookings AS bookings FROM ( -- Time Spine SELECT - subq_6.ds AS metric_time__day - FROM ***************************.mf_time_spine subq_6 - ) subq_5 + subq_5.ds AS metric_time__day + FROM ***************************.mf_time_spine subq_5 + ) subq_4 LEFT OUTER JOIN ( -- Aggregate Measures SELECT - subq_3.metric_time__day - , subq_3.booking__is_instant - , SUM(subq_3.bookings) AS bookings + subq_2.metric_time__day + , subq_2.booking__is_instant + , SUM(subq_2.bookings) AS bookings FROM ( -- Constrain Output with WHERE SELECT - subq_2.metric_time__day - , subq_2.booking__is_instant - , subq_2.bookings + subq_1.metric_time__day + , subq_1.booking__is_instant + , subq_1.bookings FROM ( + -- Metric Time Dimension 'ds' -- Pass Only Elements: ['bookings', 'booking__is_instant', 'metric_time__day'] SELECT - subq_1.metric_time__day - , subq_1.booking__is_instant - , subq_1.bookings + subq_0.ds__day AS metric_time__day + , subq_0.booking__is_instant + , subq_0.bookings FROM ( - -- Metric Time Dimension 'ds' + -- Read Elements From Semantic Model 'bookings_source' SELECT - subq_0.ds__day - , subq_0.ds__week - , subq_0.ds__month - , subq_0.ds__quarter - , subq_0.ds__year - , subq_0.ds__extract_year - , subq_0.ds__extract_quarter - , subq_0.ds__extract_month - , subq_0.ds__extract_day - , subq_0.ds__extract_dow - , subq_0.ds__extract_doy - , subq_0.ds_partitioned__day - , subq_0.ds_partitioned__week - , subq_0.ds_partitioned__month - , subq_0.ds_partitioned__quarter - , subq_0.ds_partitioned__year - , subq_0.ds_partitioned__extract_year - , subq_0.ds_partitioned__extract_quarter - , subq_0.ds_partitioned__extract_month - , subq_0.ds_partitioned__extract_day - , subq_0.ds_partitioned__extract_dow - , subq_0.ds_partitioned__extract_doy - , subq_0.paid_at__day - , subq_0.paid_at__week - , subq_0.paid_at__month - , subq_0.paid_at__quarter - , subq_0.paid_at__year - , subq_0.paid_at__extract_year - , subq_0.paid_at__extract_quarter - , subq_0.paid_at__extract_month - , subq_0.paid_at__extract_day - , subq_0.paid_at__extract_dow - , subq_0.paid_at__extract_doy - , subq_0.booking__ds__day - , subq_0.booking__ds__week - , subq_0.booking__ds__month - , subq_0.booking__ds__quarter - , subq_0.booking__ds__year - , subq_0.booking__ds__extract_year - , subq_0.booking__ds__extract_quarter - , subq_0.booking__ds__extract_month - , subq_0.booking__ds__extract_day - , subq_0.booking__ds__extract_dow - , subq_0.booking__ds__extract_doy - , subq_0.booking__ds_partitioned__day - , subq_0.booking__ds_partitioned__week - , subq_0.booking__ds_partitioned__month - , subq_0.booking__ds_partitioned__quarter - , subq_0.booking__ds_partitioned__year - , subq_0.booking__ds_partitioned__extract_year - , subq_0.booking__ds_partitioned__extract_quarter - , subq_0.booking__ds_partitioned__extract_month - , subq_0.booking__ds_partitioned__extract_day - , subq_0.booking__ds_partitioned__extract_dow - , subq_0.booking__ds_partitioned__extract_doy - , subq_0.booking__paid_at__day - , subq_0.booking__paid_at__week - , subq_0.booking__paid_at__month - , subq_0.booking__paid_at__quarter - , subq_0.booking__paid_at__year - , subq_0.booking__paid_at__extract_year - , subq_0.booking__paid_at__extract_quarter - , subq_0.booking__paid_at__extract_month - , subq_0.booking__paid_at__extract_day - , subq_0.booking__paid_at__extract_dow - , subq_0.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 - , subq_0.guest - , subq_0.host - , subq_0.booking__listing - , subq_0.booking__guest - , subq_0.booking__host - , subq_0.is_instant - , subq_0.booking__is_instant - , subq_0.bookings - , subq_0.instant_bookings - , subq_0.booking_value - , subq_0.max_booking_value - , subq_0.min_booking_value - , subq_0.bookers - , subq_0.average_booking_value - , subq_0.referred_bookings - , subq_0.median_booking_value - , subq_0.booking_value_p99 - , subq_0.discrete_booking_value_p99 - , subq_0.approximate_continuous_booking_value_p99 - , subq_0.approximate_discrete_booking_value_p99 - 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 - ) subq_1 - ) subq_2 + 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 + ) subq_1 WHERE booking__is_instant - ) subq_3 + ) subq_2 GROUP BY - subq_3.metric_time__day - , subq_3.booking__is_instant - ) subq_4 + subq_2.metric_time__day + , subq_2.booking__is_instant + ) subq_3 ON - subq_5.metric_time__day = subq_4.metric_time__day - ) subq_7 + subq_4.metric_time__day = subq_3.metric_time__day + ) subq_6 WHERE booking__is_instant -) subq_8 +) subq_7 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 476eccde2c..1fad5414e5 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 @@ -12,10 +12,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 + subq_13.ds AS metric_time__day + , subq_11.booking__is_instant AS booking__is_instant + , subq_11.bookings AS bookings + FROM ***************************.mf_time_spine subq_13 LEFT OUTER JOIN ( -- Constrain Output with WHERE -- Aggregate Measures @@ -32,14 +32,14 @@ FROM ( , is_instant AS booking__is_instant , 1 AS bookings FROM ***************************.fct_bookings bookings_source_src_28000 - ) subq_11 + ) subq_9 WHERE booking__is_instant GROUP BY metric_time__day , booking__is_instant - ) subq_13 + ) subq_11 ON - subq_15.ds = subq_13.metric_time__day - ) subq_16 + subq_13.ds = subq_11.metric_time__day + ) subq_14 WHERE booking__is_instant -) subq_17 +) subq_15